Jump to content

Number of Days or months


manuelgod

Recommended Posts

Hi, I tried looking around but couldn't find a source on how to add days OR months to a date in the following format 2007/01/29

 

It would be nice if someone could post such a script that will display the future date  depending the amount of months OR the number of days the user inputs. So if the user start date is 2007/01/31 and the user type 1 month the script will display 2007/02/01 to compensate for the leap years and months that are less then the one set.

 

Anyone with such a script?

 

Thank you in advance!

 

Link to comment
https://forums.phpfreaks.com/topic/37574-number-of-days-or-months/
Share on other sites

You cant do it on a string like '2007/01/29', you need to convert it to a timestamp first.

$date_ts = strtotime('2007/01/29');

//then say you wanted to add 4 weeks to that date and print it to the user.
$one_month_from_now = strtotime("+4 week",$date_ts);
echo date("Y/m/d",$one_month_from_now);

strtotime is a really cool and powerful function, http://au3.php.net/strtotime

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.