Find last day of a month in PHP

Published 11 Aug 2012 in Development, PHP & MySQL by ZigPress

Here’s a simple trick to find the last day of a month using PHP.

$date_of_last_day = date("Y-m-t", mktime(0, 0, 0, $month, 1, $year));

This will give you the last day of any given month/year combination in the form YYYY-MM-DD.

For example, if you pass in a month of 2 (February) and a year of 2004, the result will be 2004-02-29 (2004 was a leap year).

Like I said, simple :)


  1. On 09 Nov 2012 at 14:25, freeadboardview said:

    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.

  2. On 13 Nov 2012 at 08:10, Rabia Akram said:

    Fabulous…thanks a million.I love PHP ….a simple solution for practically everything.

  3. On 15 Nov 2012 at 16:55, Michael said:

    Nice little trick, thanks guys! :D