I have a date which is saved in a regular string.
// format = DD-MM-YYYY
$date = "10-12-2011";
How can I get the date-string +1 day so: 11-12-2011?
I have a date which is saved in a regular string.
// format = DD-MM-YYYY
$date = "10-12-2011";
How can I get the date-string +1 day so: 11-12-2011?
$date = date('d-m-Y', strtotime("+1 day", strtotime("10-12-2011")));
If you're trying to overwrite $date, Aaron's answer works great. But if you need the new day saved into a separate variable as I did, this works:
$date = strtotime('10-12-2011'); // your date
$newDate = date('d-m-Y', strtotime("+1 day", $date)); // day after original date
You should be using DateTime
class for working with dates. Using strtotime()
might not be the best choice in the long run.
To add 1 day to the data using DateTime you can use modify()
method.
$newDate = date_create_from_format('d-m-Y', $date)
->modify('+1 day')
->format('d-m-Y');
if you want today +$i day
$today = date('Y-m-d');
$tomorrow = strtotime($today." +".$i." day");
You can either use the date function to piece the date together manually (will obviously require to check for leap years, number of days in current month etc) or get strtotime and convert what you get via the date function parsing the timestamp you got from strtotime as the second argument.