Posted By

tasmanweb on 04/28/11


Tagged

php month time date function


Versions (?)

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


 / Published in: PHP
 

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

  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  

You need to login to post a comment.