Get Previous,next month first,last date in php

by Jayanthi 2012-09-11 17:16:59

Get Previous,next month first,last date in php

$date='2012-03-05 12:00:00';

$m=date('m',strtotime($date));
$y=date('Y',strtotime($date));

$date = mktime( 0, 0, 0, $m, 1, $y );

echo "Previous month first Date:".$pfdate= strftime( '%Y-%m-%d', strtotime( '-1 month', $date ) );

echo "Next month first Date:".$nfdate= strftime( '%Y-%m-%d', strtotime( '+1 month', $date ) );

echo "
";
echo "Previous month Last Date:".date("Y-m-t",strtotime($pfdate));
echo "Next month Last Date:".date("Y-m-t",strtotime($nfdate));
?>

Tagged in:

873
like
0
dislike
0
mail
flag

You must LOGIN to add comments