Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.