in reply to Counting number of a particular day of the month.
#!/usr/bin/perl -wl use strict; use Date::Calc 'Nth_Weekday_of_Month_Year'; sub max_days_in_month { my $day = $_[0]; # Monday is 1 my $month = $_[1]; # January is 1 my $year = $_[2]; scalar grep {Nth_Weekday_of_Month_Year($year, $month, $day, $_ +)} 1..5; } print "There are ", max_days_in_month(1, 6, 2002), " Mondays in Ju +ne 2002."; print "There are ", max_days_in_month(6, 6, 2002), " Sundays in Ju +ne 2002."; __END__ Prints: There are 4 Mondays in June 2002. There are 5 Sundays in June 2002. (Good news for those for prefer Sundays to Mondays)
--
John.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Counting number of a particular day of the month.
by ninja-joe (Monk) on Jun 01, 2002 at 14:21 UTC |