I have a PHP date in the form of 2013-01-22
and I want to get tomorrows date in the same format, so for example 2013-01-23
.
How is this possible with PHP?
You can use the date function. I'm using strtotime to get the timestamp to that day ; there are other solutions, like mktime , for instance.
The strtotime() function parses an English textual datetime into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT). Note: If the year is specified in a two-digit format, values between 0-69 are mapped to 2000-2069 and values between 70-100 are mapped to 1970-2000.
To get yesterday's date in PHP simply use the DateTime class and instantiate it with the constructor parameter 'yesterday' Then you can format the DateTime object with the format method.
PHP date_diff() Function $date2=date_create("2013-12-12"); $diff=date_diff($date1,$date2);
Use DateTime
$datetime = new DateTime('tomorrow'); echo $datetime->format('Y-m-d H:i:s');
Or:
$datetime = new DateTime('2013-01-22'); $datetime->modify('+1 day'); echo $datetime->format('Y-m-d H:i:s');
Or:
$datetime = new DateTime('2013-01-22'); $datetime->add(new DateInterval("P1D")); echo $datetime->format('Y-m-d H:i:s');
Or in PHP 5.4+:
echo (new DateTime('2013-01-22'))->add(new DateInterval("P1D")) ->format('Y-m-d H:i:s');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With