Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: comparing dates

by andreychek (Parson)
on Oct 17, 2001 at 03:59 UTC ( [id://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

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

    -Blake

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-26 01:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found