I have this date time format in string \"11:56:41, 11/22/2011\".
Here\'s what I want:
Compare two date time strings like.
$date1 = \"11:56:41
One more solution that uses the overloaded comparisons after converting the times to Time::Piece
objects. Creating the objects may be overkill for something simple, but they can become very useful if you need to do other things with the times.
use Time::Piece;
my $dateformat = "%H:%M:%S, %m/%d/%Y";
my $date1 = "11:56:41, 11/22/2011";
my $date2 = "11:20:41, 11/20/2011";
$date1 = Time::Piece->strptime($date1, $dateformat);
$date2 = Time::Piece->strptime($date2, $dateformat);
if ($date2 < $date1) {
do something...
} else {
do nothing...
}