LupoX has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks!

Please help me to add knowledge to my brain.

Given following snippet:

use Time::Local; $from_year = $from_year - 1900; $from_month = $from_month - 1; $from = timelocal(0,0,0,$from_day,$from_month,$from_year); $to_year = $to_year - 1900; $to_month = $to_month - 1; $to = timelocal(0,0,0,$to_day,$to_month,$to_year); $days_between = ( ($to - $from) / (60 * 60 * 24) );

Now I use this values for input....

$from_day = 2; $from_month = 2; $from_year = 2002; $to_day = 5; $to_month = 2; $to_year = 2002;

.....and get the right result: $days_between = 3

But now to my confusion: I use this values......

$from_day = 2; $from_month = 2; $from_year = 2002; $to_day = 2; $to_month = 5; $to_year = 2002;

....the result ist not even: $days_between = 88.95...

Who can enlighten me?

Thanks for your experience-sharing!

Georg

Replies are listed 'Best First'.
Re: Time::Local -> timelocal()
by fglock (Vicar) on Sep 25, 2002 at 17:20 UTC

    Try it again with  timegm() - you might be getting a daylight savings transition.

    From the Time::Local docs:

    We just assume that we're translating a GMT time, and then fudge it when we're done for the timezone and daylight savings arguments. Note that the timezone is evaluated for each date because countries occasionally change their official timezones. Assuming that localtime() corrects for these changes, this routine will also be correct. The daylight savings offset is currently assumed to be one hour.
Re: Time::Local -> timelocal()
by lestrrat (Deacon) on Sep 25, 2002 at 19:19 UTC

    This is not a direct answer to your question, but I think the correct way to do that is to use Delta_Days function from Date::Calc :)

Re: Time::Local -> timelocal()
by MZSanford (Curate) on Sep 26, 2002 at 13:43 UTC