PHP Logo

PHP: Find the last day of the month

Posted by

In PHP you can pass the t format character to the date() function in order to get the number of days in the month. Since this number also happens to be the date of the last day of the month, you can use this to your advantage:

Get the last day of the current month:

<?php
echo date('t F Y'); // e.g. 31 December 2011
?>

Get the last day of the month a timestamp falls in:

<?php
echo date('t F Y', 132456628); // e.g. 31 March 1974
?>

Leave a Reply

Your email address will not be published. Required fields are marked *