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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

date handling/arithmetic

Status
Not open for further replies.

HOTLIPS

Technical User
Dec 5, 2000
55
GB
Help ... How do I add say 6 months or 12 months to a date........... ie say add 6 months to 2003-9-25
Thanks
 
i think u have to use the mktime function along with the date function, i ts pretty simple...

Known is handfull, Unknown is worldfull
 
It depends on your math.

Do you want to add six calendar months, or 180 days?


To add six calendar months (2003-09-15 plus 6 months would be 2004-03-15), I'd split the date at the dashes, add 6 to the month value, and if that value is more than 12, subtract 12 from it and add 1 to the year.


To add 180 days, I'd use strtotime() to convert the date string to a Unix time tick, then add 60 seconds/minute * 60 minutes/hour * 24 hours/day * 180 days to the tick number, then use date() to convert it back to a date string.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top