in reply to subroutine for calculating day since 1900 needed
sub days_since_1900 { use integer; my ($d, $m, $y) = @_; # $d: 1-based Day of the month (1..31) # $m: 0-based Month (Jan=0..Dec=11) # $y: 2 or 4 digit year $y += 1900 if $y < 1000; my $i = ($m + 10) % 12; my $j = $y - $i/10; return $d + 365*$j + $j/4 - $j/100 + $j/400 + ($i*306 + 5)/10 - 693 +902; }
Based on Time::Local's internals.
Update: Fixed a misnamed variable. Thanks liverpole.
Update: Added missing - 693902. Thanks rodion. Where was my head when I posted this?!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: subroutine for calculating day since 1900 needed
by rodion (Chaplain) on May 12, 2006 at 20:13 UTC | |
|
Re^2: subroutine for calculating day since 1900 needed
by Anonymous Monk on Jul 16, 2016 at 23:02 UTC |