in reply to counting days
which, for me and now, prints:use Time::Local; # module comes with Perl, so don't worry my $start = timelocal(0, 0, 0, 9, 1, 2004); printf "Days since Feb 9: %d days\n", int((time - $start)/(24*60*60));
Days since Feb 9: 58 days
It does have a problem with summertime (AKA dayligh saving time), though... One day didn't have 24 hours, but just 23. It'll count multiples of 24 hours alright, but it won't switch over at midnight any more.
Update If you really want calendar days, not just multiples of 24 hours, here's a quick fix. Use gmtime/timegm() instead of localtime/timelocal() for the calculations, as that doesn't care about daylight saving time. So fake it, act as if the current local time is actually gmtime, and take the calculations from there. Updated code that does that:
use Time::Local; # module comes with Perl, so don't worry my $start = timegm(0, 0, 0, 9, 1, 2004); printf "Days since Feb 9: %d days\n", int((timegm(localtime) - $start) +/(24*60*60));
Thanks to the fact that timegm() takes its parameters just the way localtime() returns them in list context, while ignoring exces parameters, the interface between the two is very simple.
|
|---|