Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
We don't bite newbies here... much
 
PerlMonks  

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

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

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


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 16: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
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.