Pankaj Khurana Pankaj Khurana - 1 year ago 50
PHP Question

Add number of days to a date

I want to add number of days to current date:
I am using following code:

echo $date = strtotime(date("Y-m-d", strtotime($date)) . " +".$i."days");

But instead of getting proper date i am getting this:

Please suggest.

Answer Source

This should be

echo date('Y-m-d', strtotime("+30 days"));


expects to be given a string containing a US English date format and will try to parse that format into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 UTC), relative to the timestamp given in now, or the current time if now is not supplied.

while date

Returns a string formatted according to the given format string using the given integer timestamp or the current time if no timestamp is given.

See the manual pages for

and their function signatures.