问题
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?
回答1:
Similar post
$date = date('d-m-Y', strtotime("+1 day", strtotime("10-12-2011")));
回答2:
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
回答3:
if you want today +$i day
$today = date('Y-m-d');
$tomorrow = strtotime($today." +".$i." day");
回答4:
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.
回答5:
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');
来源:https://stackoverflow.com/questions/8457661/php-string-date-1-day-equals