Saturday, January 8, 2011

get last day of the previous month in PHP

Get Last Day Of The Previous Month


$date = "2010-12-31";

list($yr,$mn,$dt)  = split('-', $date);         // separate year, month and date
$time_stamp        = mktime(000$mn0$yr);   // Create time stamp
$last_month_last_day = date("Y-m-t", $time_stamp);

echo "last_month : " . $last_month";
ouptut : 2010-11-30...

No comments: