jj20051 Posted July 15, 2010 Share Posted July 15, 2010 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 :'(. Quote Link to comment https://forums.phpfreaks.com/topic/207893-strtotime-problem/ Share on other sites More sharing options...
Pikachu2000 Posted July 15, 2010 Share Posted July 15, 2010 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>"; Quote Link to comment https://forums.phpfreaks.com/topic/207893-strtotime-problem/#findComment-1086768 Share on other sites More sharing options...
PFMaBiSmAd Posted July 15, 2010 Share Posted July 15, 2010 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')); Quote Link to comment https://forums.phpfreaks.com/topic/207893-strtotime-problem/#findComment-1086776 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.