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
adding months to date
Moderator: General Moderators
-
bigdavemmu
- Forum Newbie
- Posts: 22
- Joined: Wed Oct 26, 2005 4:01 am
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
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
Take a look at date_modify()
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
Grim... wrote:Take a look at date_modify()
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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.