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


/ Published in: PHP
Save to your folder(s)

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


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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.