in reply to how can i find number of days in a given year and month

my @monthDays= qw( 31 28 31 30 31 30 31 31 30 31 30 31 ); sub MonthDays { my $month= shift(@_); my $year= @_ ? shift(@_) : 1900+(localtime())[5]; if( $year <= 1752 ) { # Note: Although September 1752 only had 19 days, # they were numbered 1,2,14..30! return 19 if 1752 == $year && 9 == $month; return 29 if 2 == $month && 0 == $year % 4; } else { return 29 if 2 == $month and 0 == $year%4 && 0 == $year%100 || 0 == $year%400; } return $monthDays[$month-1]; }

This covers Julian and Gregorian dates and uses Julian month lengths even prior to the Julian calendar.

Replies are listed 'Best First'.
Re: Answer: how can i find number of days in a given year and month
by larryk (Friar) on Jul 17, 2001 at 20:25 UTC
    # your 0 == $year%4 && 0 == $year%100 || 0 == $year%400; # should be 0 == $year%4 && 0 != $year%100 || 0 == $year%400;

    "Argument is futile - you will be ignorralated!"