Return to Snippet

Revision: 45265
at April 28, 2011 01:11 by tasmanweb


Initial Code
/*
returns number of days in the month taking leap-years into account.
input month as a number (1=january etc.) and year.
eq. echo month_length(2,2004); // days in feb 2004.
*/
function month_length($month,$year,$scale=0){
  $monthdays = array(1=>31, 3=>31, 4=>30, 5=>31, 6=>30, 7=>31, 8=>31, 9=>30, 10=>31, 11=>30, 12=>31);
  if ($month==2){
     $monthdays[2] = (date("L", mktime( 0, 0, 0, 2, 1, date($year))) ? 29 : 28);
  }
  return $monthdays[$month];
}

Initial URL

                                

Initial Description
Returns the number of days in the month taking leap-years into account.

Initial Title
month_length: number of days in the month taking leap-years into account

Initial Tags
php, date, function

Initial Language
PHP