PHP: Find the last day of the month

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:

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

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

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