# Return the day (1..7) that the first day of the given month/year falls # on. Uses "Zeller's Confluence", which I don't claim to understand. # sub Day_of_Week { my($year, $month, $day) = @_; # $month in (1..12), $year as YYYY $month-=1; if ( $month < 2 ) { $month += 12; --$year; } my $z1 = (26 * ($month + 2)) / 10; my $z2 = int((125 * $year) / 100); my $day_of_week = ($z1 + $z2 - int($year / 100) + int($year / 400)) % 7; return $day_of_week ? $day_of_week : 7; }