Dinuka Thilanga Dinuka Thilanga - 1 month ago 7
PHP Question

What is best solution to get next and previous month from given date php

I want to get next and previous month from given date. this is my code.

$month = '2011-01-20';

$prevMOnth = funP($month);
$nextMonth = funN($month);

what is best solution to do that.

Answer
$next_month_ts = strtotime('2011-01-20 +1 month');
$prev_month_ts = strtotime('2011-01-20 -1 month');

$next_month = date('Y-m-d', $next_month_ts);
$prev_month = date('Y-m-d', $prev_month_ts);