Last Day of a Given Month

Description: Returns a timestamp of the last day of a given month/year. Great for calendar/scheduling applications.
Tested Platform: PHP 5
Language: PHP
// Returns the timestamp for the last day of a given month for a given year. 
// Expects: Month starting from 1 index and 4 digit year
// Returns: Timestamp for last day of given month/year

// Remember to set default timezone (Here we are using west coast US)
date_default_timezone_set('US/Pacific');

function lastDayOfMonth($month, $year) {
     return mktime(23, 59, 59, $month + 1, 0, $year);
}

Submitted: December 24, 2012

Return to the snippets listing