Solved

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

Posted on 2007-11-14
6
1,044 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
6 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 30 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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 20 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…

856 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