[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 790
  • Last Modified:

How to compare Date fields in perl

In a Perl script, I'm selecting records from database, some of the records are Date fields, Selected using to_char in "dd-mon-yyyy hh:24mi:ss" format.
I need to compare between another date field to check if one date is older than the other, how do i do that
0
prasen120998
Asked:
prasen120998
  • 3
1 Solution
 
ozoCommented:
(join'',(split/[- ]/,$one)[2,1,0,3]) cmp join'',(spit/[- ]/,$another)[2,1,0,3]
0
 
ozoCommented:
(join'',(split/[- ]/,$one)[2,1,0,3]) cmp join'',(split/[- ]/,$another)[2,1,0,3]
0
 
prasen120998Author Commented:
Hi ozo, the above solution is not working.
I've two date fields, DBDate as say 02-NOV-2005 21:05:22
and sysdate as 13-OCT-2007 10:25:15
How do I check to see if sysdate is greater or less than DBdate

I can check by converting them as yyyymmddhh24miss, but then its tedious, is there anything simpler
0
 
ozoCommented:
$DBDate = "02-NOV-2005 21:05:22";
$sysdate = "13-OCT-2007 10:25:15";
my %mon;
@mon{qw(JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOW DEC)} = '01'..'12';
s/(\d\d)-(\w{3})-(\d{4})/$3$mon{$2}$1/ for $DBDate,$sysdate;
print qw(equal greater less)[$sysdate cmp $DBDate];
0
 
GavieroCommented:
Hi, you could use:

http://search.cpan.org/~sbeck/Date-Manip-5.48/Manip.pod

And parse both dates, in order to compare them.


The library make it quite easy
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now