Perl parse string to time

Hi,
I have got this value 18:21:23.330 in one of my variables.
Now I need to parse this time to something.
And then I have to compare it with 2 times, let's say, 15:00 hrs to 23:00 hrs.
Can Date::Manip rescue me from this horrifying situation?
I am quite new to Perl and especially this Date::Manip module.
Again, Date::Calc is not an option here :frowning:
Thanks :slight_smile:

One way to do this:

$
$ cat test_script.pl
#/usr/bin/perl -w
use Date::Manip;

$time1 = "18:21:23";
$time2 = "19:21:23";

$date1 = ParseDate("01/01/2009 ".$time1);
$date2 = ParseDate("01/01/2009 ".$time2);

print UnixDate($date1,"date1 = %e-%b-%Y %T\n");
print UnixDate($date2,"date2 = %e-%b-%Y %T\n");

$flag = Date_Cmp($date1, $date2);
if ($flag < 0) {
  print "date1 is earlier\n";
} elsif ($flag == 0) {
  print "The two dates are identical\n";
} else {
  print "date2 is earlier\n";
}

$
$ perl test_script.pl
date1 =  1-Jan-2009 18:21:23
date2 =  1-Jan-2009 19:21:23
date1 is earlier
$
$

Of course, I hope you do realize that comparing two "times" e.g. 15:00 hrs and 23:00 hrs is meaningless because 15:00 hrs could be less than, or greater than, or even equal to 23:00 hrs.

You do need the date, month, year in order to make sense out of the "time", and I've assumed that you want to compare "times" of the same day.

tyler_durden