How can I get the last day of the month in PHP?
Given:
$a_date = \"2009-11-23\"
I want 2009-11-30; and given
$a_dat
I am late but there are a handful of easy ways to do this as mentioned:
$days = date("t");
$days = cal_days_in_month(CAL_GREGORIAN, date('m'), date('Y'));
$days = date("j",mktime (date("H"),date("i"),date("s"),(date("n")+1),0,date("Y")));
Using mktime() is my go to for complete control over all aspects of time... I.E.
echo "
".date("Y-n-j",mktime (date("H"),date("i"),date("s"),(11+1),0,2009));
Setting the day to 0 and moving your month up 1 will give you the last day of the previous month. 0 and negative numbers have the similar affect in the different arguements. PHP: mktime - Manual
As a few have said strtotime isn't the most solid way to go and little if none are as easily versatile.