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
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
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.
strtotime( "+1 month", strtotime( $time ) );
this returns a timestamp that can be used with the date function
$time = strtotime("2010-12-11");
$final = date("Y-m-d", strtotime("+1 month", $time));
// Final will have the date you're looking for.