P0w3rK!d has asked for the wisdom of the Perl Monks concerning the following question:

Given a min-time/date and max-time/date... What is the easiest way to determine that the current time/date falls within the aforementioned times?

Replies are listed 'Best First'.
Re: MasteringTime
by tadman (Prior) on Jul 09, 2001 at 22:20 UTC
    The "easiest" way is to use localtime and/or Time::Local to convert from whatever date/time format you are using into the standard UNIX time_t format. This is a numerical value representing the number of seconds elapsed from January 1, 1970 GMT. Since it is just a number at this point, it is very easy to do math and comparisons on two values, even from different time-zones, or from the same time zone during Daylight Savings and Standard Time.

    As such, once you have converted your min and max to simple time_t format, it is a case of comparison like:
    if ($the_time >= $min_time && $the_time <= $max_time) { # ... Do stuff? }
Re: MasteringTime
by voyager (Friar) on Jul 09, 2001 at 22:33 UTC
Re: MasteringTime
by lhoward (Vicar) on Jul 09, 2001 at 22:22 UTC
    Convert to a common format (such as: seconds since Jan 1, 1970; or YYYYMMDDhhmmss) and compare. Time::ParseDate is very handy.
      Or, use Date::Manip.

      It has more features and I like it better than Time::ParseDate, except that it is very big and heavy, so its an overkill if you are just using only one or two of its features.

      /prakash

Re: MasteringTime
by pltommyo (Initiate) on Jul 10, 2001 at 00:07 UTC
    For a small number of comparisons, DateManip is nifty and has a lot of functionality. But I know when I tried it with about 50M compares to do it sort of took a long time :-) Tommy O
      Did you try benchmarking it (Date::Manip) with your data set and compare it with the alternative (Time::ParseDate)?

      That would be interesting to know.

      /prakash