Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

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!

Comment on Re: comparing dates
Replies are listed 'Best First'.
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


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2015-11-29 04:53 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (746 votes), past polls