[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Comparing dates



At 19.02 +0100 1999.11.21, Lasar Liepins wrote:
>>From a text log file I have extracted the minutes, hours, day, month and
>year
>for to points in time. Now I want to know how much time has passed between
>them.

Use Time::Local to convert it to number of seconds since the epoch.

>In my first beta of the script in which I need this I just used this:
>
>$time1 = $min1 + ( $hrs1 * 60 );
>$time2 = $min2 + ( $hrs2 * 60 );
>$connection_time = $time2 - $time1;

    use Time::Local;
    $time1 = timelocal($sec1, $min1, $hours1, $mday1, $mon1, $year1);
    $time2 = timelocal($sec2, $min2, $hours2, $mday2, $mon2, $year2);

Then $time2-$time1.  For $sec, you can make it 0.  Remember that $mon is
month - 1 (Jan=0, Dec=11) and year is year-1900 (1999=99, 2000=100).

Time::Local is flawed; I don't know in what way, but I have seen people
discuss problems with it.  It should work in most cases, though.

-- 
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org