Showing posts with label date. Show all posts
Showing posts with label date. Show all posts

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(0, 0, 0, $mn, 0, $yr);   // Create time stamp
$last_month_last_day = date("Y-m-t", $time_stamp);

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

get last day of the current month in PHP

Get Last Day Of The Current Month


To get the last day of the month so got this piece of code.
try the following code all are different format....

date('Y-m-d', strtotime('-1 second', strtotime(date('m') . '/01/' . date('Y') . '00:00:00')))

date(“Y-m-d”,mktime(0,  0,  0, (date(‘m’) + 1), 0, date(‘Y’)))

strtotime(‘+1 month -1 second ‘ . date(‘Y’) . ’-’ . date(‘m’) . ’-01′ );

date(“Y-m-t”); //t = number of days in the month

date(“Y-m-d’,mktime(0, 0, 0,  2, 32, 2008));

date(‘t’,strtotime(“last month”));

date(‘D Y-m-t’, strtotime(“last month”))