Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: date comparing

by mem (Acolyte)
on Aug 06, 2002 at 07:43 UTC ( [id://187955]=note: print w/replies, xml ) Need Help??


in reply to date comparing

Just a tip: if you have to compare dates and want to do it yourself, the general algorithm goes like this:

  • Parse the date
  • Convert to seconds since the epoch
  • Compare that. It can't get easier than $t1 <=> $t2

Since the parsing task might be non-trivial, I like the Date::Parse module from TimeDate, but there are other date parsing modules in CPAN, and a bunch of them do date comparisons, too.

Replies are listed 'Best First'.
Re: Re: date comparing
by demerphq (Chancellor) on Aug 06, 2002 at 08:59 UTC
    Actually what you say is correct for determining time elapsed between two dates, but not for simply determining if two dates are inorder (what "compare" normally means). If the dates are in ISO or DIN compliant format then they are readily compared using the eq operator.

    Just another reason for discarding outdated conventional date formats like dd/mm/yy or the even more bizarre mm/dd/yy.

    print POSIX::strftime("%Y%m%d%H%M%S",localtime);
    Sorry, I guess i'm in a pedantic mood this morning. :-)

    Yves / DeMerphq
    ---
    Writing a good benchmark isnt as easy as it might look.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://187955]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-03-29 15:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found