Jump to content

Incrementing a date by one day


svgmx5

Recommended Posts

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)

Link to comment
Share on other sites

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;

Link to comment
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.