Page 1 of 1
adding months to date
Posted: Fri Jan 19, 2007 6:24 am
by hame22
Hi
How can i take todays date and add an extra number of months to it to get a new date. For example create date in 5 months time.
Thanks in advance
Posted: Fri Jan 19, 2007 6:31 am
by bigdavemmu
Request the different parts of a date from PHP then add what you need to any part of it.
For example:
$days = date(d);
$month = date(m) + 4;
$year = date(Y);
Then add them together to create a date in the order you wish... For example:
$CompleteDate = $days.'-'.$month.'-'.$year;
This will print 19-01-2007
Hope this helps!
David
Posted: Fri Jan 19, 2007 6:39 am
by hame22
thanks the proble is it doesnt take into the year, i think there may be an easier way using MYSQL's DATE_ADD
Posted: Fri Jan 19, 2007 6:44 am
by Grim...
Take a look at
date_modify()
Posted: Fri Jan 19, 2007 9:30 am
by Kieran Huggins

sweet!
Posted: Fri Jan 19, 2007 10:09 am
by pickle
What format is the date in? If your're using a UNIX timestamp, use
strtotime(). If you're using a MySQL stamp, use DATE_ADD(). If you're using something else, convert it to a UNIX timestamp.
Posted: Fri Jan 19, 2007 1:31 pm
by onion2k
If you're stuck with PHP4 you could use mktime() rather than date_modify().