Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: comparing dates

by andreychek (Parson)
on Oct 17, 2001 at 03:59 UTC ( #119289=note: print w/ replies, xml ) Need Help??


in reply to comparing dates

Ahhh, yes.. comparing dates. I've always found that the absolute easiest way to compare two dates is by first converting them to seconds (seconds since the epoch, to be specific).

You didn't show the particular format of date which you are using -- however, assuming that you have any kind of date format but seconds since the epoch, you can use the Time::Local module to convert it for you. Once you convert it to seconds, you're simply comparing two integers, which is very trivial.

If you read the post Re: Within A Date Time Range, I offered an example implementation on how this might be done. However, if you make use of Super Search, there's bound to be some other examples of that too. Also, you may want to check out Date format manipulation, which was posted just a few hours before your question.

Good luck!
-Eric


Comment on Re: comparing dates
Re: Re: comparing dates
by blakem (Monsignor) on Oct 17, 2001 at 04:10 UTC
    Interesting, I've always used POSIX::mktime to convert a localtime array back into a timestamp. Does anyone else have a preference or rationale why one might be used over the other?
    #!/usr/bin/perl -wT use strict; use Time::Local; use POSIX; my @localtimearr = localtime; print Time::Local::timelocal(@localtimearr), "\n"; print POSIX::mktime(@localtimearr), "\n"; =sample OUTPUT 1003277170 1003277170

    -Blake

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (12)
As of 2014-09-30 21:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (384 votes), past polls