Kichu
Kichu

Reputation: 3267

How can I find the date that is 1 day later than another date in PHP?

How can I find the next day's date after a given date.

For example, I have a date 2011-11-31. How can I get the next date (2011-12-01) using PHP?

Similarly, how would I get the previous day's date?

Upvotes: 0

Views: 901

Answers (2)

Manigandan Arjunan
Manigandan Arjunan

Reputation: 2265

You can use the strtotime() function in php:

$date="2011-11-11";
$nextdate = date('Y-m-d', strtotime($date . " +1 day"));
echo $nextdate;

It will echo as "2011-11-12".

Similarly to find the previous date use:
$nextdate = date('Y-m-d', strtotime($date . " -1 day"));

It will echo as "2011-11-10".

Upvotes: 0

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324750

$nextdate = date("Y-m-d",strtotime($olddate." +1 day"));

Upvotes: 5

Related Questions