Jump to content

Strtotime Problem?


jj20051

Recommended Posts

I'm working with a strtotime  function that doesn't seem to be working correctly. I'm trying to add 1 week to today's current date and store than in a variable with the format: month.day.year, but my code for some reason is displaying 1970 as the year and the wrong month and day as well. Suggestions welcome :)

 

$currentDate = date("m.d.Y");// current date

echo "Today's Date: ".$currentDate."<br>";

$date = strtotime(date("m.d.Y", strtotime($currentDate)) . " +1 week");
$ttldate = date('m.d.Y', $date);
echo "Date After adding one week: ".$ttldate."<br>";

 

Been trying to figure out why this won't work for about 30 minutes so any help would be appreciated  :'(.

Link to comment
https://forums.phpfreaks.com/topic/207893-strtotime-problem/
Share on other sites

The interval also needs to be converted to a unix timestamp so the math can be performed.

 

$currentDate = date("m.d.Y");// current date

echo "Today's Date: ".$currentDate."<br>";

$date = strtotime($currentDate) + strtotime('1 week');
$ttldate = date('m.d.Y', $date);
echo "Date After adding one week: ".$ttldate."<br>";

Link to comment
https://forums.phpfreaks.com/topic/207893-strtotime-problem/#findComment-1086768
Share on other sites

You have far too many function calls strung together and the dot . format is not one that strtotime() understands - http://www.gnu.org/software/tar/manual/html_node/Calendar-date-items.html#SEC121 Also, strtotime() can do date math.

 

To get today's date + 1 week in the "m.d.Y" format -

$ttldate = date('m.d.Y', strtotime(' + 1 week'));

 

 

Link to comment
https://forums.phpfreaks.com/topic/207893-strtotime-problem/#findComment-1086776
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.