tags:

views:

79

answers:

3

hi

let i have a date like it: 2010-12-11(year-mon-day)

Now in php i want to increment it by one month. but when the month will be incremented, it will be automatically adjust years if needed.

pls help.

regards

+1  A: 

Use DateTime::add.

$start = new DateTime("2010-12-11", new DateTimeZone("UTC"));
$month_later = clone $start;
$month_later->add(new DateInterval("P1M"));

I used clone because add modifies the original object, which might not be desired.

Matthew Flaschen
+4  A: 
strtotime( "+1 month", strtotime( $time ) );

this returns a timestamp that can be used with the date function

Galen
+1  A: 
$time = strtotime("2010-12-11");
$final = date("Y-m-d", strtotime("+1 month", $time));
// Final will have the date you're looking for.
Raphael Caixeta