svgmx5 Posted November 28, 2011 Share Posted November 28, 2011 I'm having troubles incrementing a date by one day using the following format: 11-17-2011 (m-d-Y) I am attempting to use the following script: $time = strtotime("11-17-2011"); $final = date("m-d-Y", strtotime("+1 day", $time)); When i echo $final i get a whole different date "01-01-1970" Now if i switch the format around to the following: $time = strtotime("2011-11-17"); $final = date("Y-m-d", strtotime("+1 day", $time)); and i echo $final i get the right date but in that format (2011-11-18). Is there a way i can get the date in the first format?(m-d-Y) Quote Link to comment https://forums.phpfreaks.com/topic/251976-incrementing-a-date-by-one-day/ Share on other sites More sharing options...
BillyBoB Posted November 28, 2011 Share Posted November 28, 2011 nevermind i read it too fast but thats weird maybe this will help you out http://www.php.net/manual/en/datetime.formats.date.php try: $time = strtotime("11/17/2011"); $final = date("m-d-Y", strtotime("+1 day", $time)); or: $time = strtotime(str_replace("-","/","11-17-2011")); $final = date("m-d-Y", strtotime("+1 day", $time)); Quote Link to comment https://forums.phpfreaks.com/topic/251976-incrementing-a-date-by-one-day/#findComment-1291913 Share on other sites More sharing options...
Pikachu2000 Posted November 28, 2011 Share Posted November 28, 2011 The format of the date you're passing in is not in a format that's accepted by strtotime(): http://us2.php.net/manual/en/datetime.formats.date.php strtotime() takes one argument, you're passing it two. You don't need to call strtotime() twice, it will perform the addition and conversion to unix time in one operation. $time = strtotime("11/17/2011 + 1 day"); $final = date("m-d-Y", $time); echo $final; Quote Link to comment https://forums.phpfreaks.com/topic/251976-incrementing-a-date-by-one-day/#findComment-1291918 Share on other sites More sharing options...
svgmx5 Posted November 29, 2011 Author Share Posted November 29, 2011 Awesome, this did the job. Wasn't aware that the format i was using was not accepted with that function. Now i know thanks everyone! Quote Link to comment https://forums.phpfreaks.com/topic/251976-incrementing-a-date-by-one-day/#findComment-1292097 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.