Alan Hogue wrote:

> Hi,
> 
> I need to know the easiest way to translate a date (not today's date)
> into the number of seconds since 01/01/1970. I realize there is at
> least one function that turns the current date/time into this number,
> but I need to find, for instance, everything with a date/time stamp
> between 01/01/1998 and 01/01/2001. How is this done?
> 

# this sub was written by Larry Rosler
# modified by me to get rid of the 'argument isnt numeric' warnings by -w
# i found it on deja
# it takes 6 arguments
# and returns the time in epoch seconds
# or undef if the date is not valid
sub UTC_to_Epoch {
        my($year, $mon, $day, $hour, $min, $sec) = @_;
        (($year =~ m/^\d{4}$/) && ($mon =~ m/^\d{1,2}$/) && ($day =~ 
m/^\d{1,2}$/)) or return;
        ($year <= 2037) or return;
        my @m_day = (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
        $m_day[2] = 29 unless $year % 4; # OK from 1901 through 2099.

        1970 <= $year         && $year <= 2099
        && 1 <= $mon          && $mon  <= 12
        && 1 <= $day          && $day  <= $m_day[$mon]
        && 0 <= ($hour ||= 0) && $hour <= 23
        && 0 <= ($min  ||= 0) && $min  <= 59
        && 0 <= ($sec  ||= 0) && $sec  <= 59
        or return;

        # Adapted from Astronomical Computing, Sky & Telescope, May, 1984.
        24 * 60 * 60 * (367 * $year - 678972 - 40587 + int(275 * $mon / 9) + $day 
- int((int(int($year + ($mon < 9 ? -1 : 1) * int(abs($mon - 9) / 7)) / 100) 
+ 1) * 3 / 4) - int(7 * (int(($mon + 9) / 12) + $year) / 4)) + 60 * 60 * 
$hour + 60 * $min + $sec
}

Todd W

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to