Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding 1 month to a date

Status
Not open for further replies.

matthewralston

Programmer
Apr 30, 2001
12
GB
I want to get the date 1 month from now. So if today is 11/11/2002, I want to get 11/12/2002. If today is 30/01/2003 I want to get (I suppose) 02/03/2003...something like that.
In VBScript there is DateAdd(). Is there something similar in PHP?
 
If you are looking to add an arbitrary number of days to an arbitrary date, run the date string through strtotime() ( to get the Current Unix Epoch timestamp.

Then add 86400 * <number of days to add> to it. Then run that new number through date() ( ______________________________________________________________________
TANSTAAFL!
 

This will add 1 month to the date of today:
$newdate= date(&quot;Ymd&quot;, mktime(0,0,0,date(&quot;m&quot;)+1,date(&quot;d&quot;),date(&quot;Y&quot;)));
This will add 40 days to the date of today
$newdate= date(&quot;Ymd&quot;, mktime(0,0,0,date(&quot;m&quot;),date(&quot;d&quot;)+40 ,date(&quot;Y&quot;)));

date(&quot;Ymd&quot;) will give this 20021125. Select the format you want. Take a look in the PHP-manual.

ojf
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top