Connecting Tech Pros Worldwide Forums | Help | Site Map

How to compare dates in Perl

Member
 
Join Date: Jul 2007
Posts: 38
#1: Aug 1 '07
Hi All,

I have two dates of the following format

Wed Jul 11 18:32:46 2007

How can i compare them? I want to use comparison to run another peice of code.

Thanks in advance for your help.

Cheers,
Amit

KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#2: Aug 1 '07

re: How to compare dates in Perl


either you convert your human readable time stamps into epoch seconds using the Time::Local module, which is a core module so nothing has to be installed:

perldoc: Time::Local

Or use a dtae/time module, like DateTime, which is way more robust but comes with a steeper learning curve and may need to be installed as it is not a core module:

cpan: DateTime
Member
 
Join Date: Jul 2007
Posts: 38
#3: Aug 2 '07

re: How to compare dates in Perl


Hi Kevin,

Thanks a lot for your suggestions. I never wanted to install any module (some security reasons ;-) ) and you gave me right directions. In between i used POSIX and mktime function to convert the date into timestamp (epoch). It is working but it needs values 6 values eg sec, min, hour, day etc... i will try your suggestion.

Cheers,
Amit
Reply