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
What, already 4 hours and not a single DateTime (all hail the mighty DateTime) answer in sight? You're slacking, perl subscribers… ☻
use DateTime::Format::Strptime qw();
my $p = DateTime::Format::Strptime->new(pattern => '%T, %D', on_error => 'croak',);
my $date1 = $p->parse_datetime('11:56:41, 11/22/2011');
my $date2 = $p->parse_datetime('11:20:41, 11/20/2011');
if($date2 < $date1) {
say "$date2 comes before $date1";
} else {
say "$date2 does not come before $date1";
}
The method parse_datetime returns instances of DateTime
whose comparison operators and stringification are overloaded to DTRT.