May 12, 2011
I have came across some crazy snippets of code finding the last day of a month in php. Then I came across this very simple method. PHP date function takes a paramater as ‘t’ which gives the number of days of a month which is the last day ![]()
so
<?php
echo date(‘Y-m-t’)';
?>
will give you the last day of the month
You can use the same method to find the last method of any month/year using strtotime
<?php
echo date(‘Y-m-t’, strtotime(‘next month’));
?>
Peace of cake right ![]()
Recent Comments