?
Solved

Fastest way in PERL to  compare dates in the following form: YYYY-MM-DD hh:mm:ss

Posted on 2007-11-14
6
Medium Priority
?
1,049 Views
Last Modified: 2012-08-14
How can you compare dates in PERL with the following date format:YYYY-MM-DD hh:mm:ss
For example: 06-10-26 13:00:06 is greater than 06-10-26 11:27:28
0
Comment
Question by:angelsky
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 120 total points
ID: 20279128
if( '06-10-26 13:00:06' gt '06-10-26 11:27:28' ){ print 'greater' }
0
 
LVL 6

Expert Comment

by:Talmash
ID: 20279347
Y2K bug...
you noted YYYY and used YY...

another issue, moving to
0
 
LVL 48

Expert Comment

by:Tintin
ID: 20282910
Your description and sample data don't match.  Which is correct?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:angelsky
ID: 20287159
Sorry my mistake...
 2006-10-26 13:00:06 is greater than 2006-10-26 11:27:28
Because "2006-10-26 13:00:06 " is later than "2006-10-26 11:27:28"
0
 

Author Comment

by:angelsky
ID: 20287259
$dateA = "2006-10-26 13:00:06";
$dateB = "2006-10-26 11:27:28";

How can I say that dateA is after dateB?
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 80 total points
ID: 20287281
As ozo has already shown

$dateA = "2006-10-26 13:00:06";
$dateB = "2006-10-26 13:27:28";

if ($dateA gt $dateB) {
  print "$dateA is later than $dateB\n";
}
else {
  print "$dateB is later than $dateA\n";
}
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question