About Us

News

RSS
Find the Last Day of the Month With PHP
Google - last day of month php - and you'll get over 15,000,000 results.  It's amazing how many people have searched for this & how many roundabout ways there are to accomplish what should be a simple task.

Here is the simplest way (that I know of) to get the last day of the month using PHP.

Get last day of the current month


$lastday = date('t',strtotime('today'));

 Get last day of next month

$lastday = date('t',strtotime('next month'));

Get last day of any other month
Enter any month/day/year to get the last day of that month

$lastday = date('t',strtotime('3/1/2009'));

If you want to display the last day of this month on your website, do the following:

<?php
echo date('t',strtotime('today'));
?>

Go Back...

Cat wrote on 10/22/09 at 11:11am...
"At last!

I needed to find out the last day of a user specified month from a dropdown, and I searched and found ridiculously long complicated functions but knew there must be a simple php way of doing it and luckily I came across this blog and from it created the following

$intLastDayInChosenMonth = date('t', strtotime($dteYear.'/'.$dteMonthID.'/01'));

Thankyou!!!"
shaid wrote on 1/03/10 at 6:57am...
"Yes,
it simply brilliant!
Thank you.
http://www.askcms.com"

 


Leave a comment

Your Email Address


Your Name


Message