Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: how can i find number of days in a given year and month

by tye (Sage)
on Jul 17, 2001 at 17:16 UTC ( [id://97303]=note: print w/replies, xml ) Need Help??


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!"

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://97303]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-25 17:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found