Skip to main content
Missing Code
Inspiring
April 20, 2011
Question

Adding days to a PHP date.

  • April 20, 2011
  • 1 reply
  • 561 views

I am converting a mySQL date to PHP and then attempting to add days to it for the output. Here is what I have so far:

$tempDate = strtotime($row['duedate']);
$newDate = date("Y-m-d",$tempDate);
$fiveDaysLater = strtotime(date("Y-m-d", strtotime($newDate) . " +1 day"));

Output:

1303192800

The date I am taking from MySQL is 2011-04-19.

I really just need to output the new PHP date as something like 04/20/2011 or something similar. Any help is appreciated!

Thanks.

P.S. - If anyone knows, can you please let me know if adding enough days will take you to the next month, or will it wrap around back to the first of the month?

This topic has been closed for replies.

1 reply

Known Participant
April 20, 2011

echo date('m/j/Y', $fiveDaysLater);

Adding days will take you to the next month. It will not wrap.

Missing Code
Inspiring
April 20, 2011

Rob, thanks for the formatting help for my output.

I found the solution:

The placment of my parenthesis was wrong:

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

Here is the correct version (corrections on both lines in red):

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