Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Adding days to a PHP date.

Explorer ,
Apr 19, 2011 Apr 19, 2011

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?

TOPICS
Server side applications
565
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 19, 2011 Apr 19, 2011

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

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 19, 2011 Apr 19, 2011
LATEST

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");

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines