use warnings; use strict; use DateTime; use DateTime::Format::Strptime; my $old_str = 'Dec 19 17:01:00 2016'; # normally, $now = DateTime->now my $now = DateTime->new(year=>2016,month=>12,day=>19, hour=>17,minute=>7,second=>6,time_zone=>'America/New_York'); print "now=", $now->strftime('%Y-%m-%d-%H-%M-%S %Z'), "\n"; my $strp = DateTime::Format::Strptime->new( on_error=>'croak', pattern => '%b %d %T %Y', time_zone=>'America/New_York' ); my $old = $strp->parse_datetime($old_str); print "old=", $old->strftime('%Y-%m-%d-%H-%M-%S %Z'), "\n"; # approach one: difference my $diff_sec = $now->subtract_datetime_absolute($old) ->in_units('seconds'); print "diff_sec: $diff_sec (", sprintf("%.1f",$diff_sec/60), " minutes)\n"; # approach two: compare to another DateTime my $halfago = $now->clone->subtract(minutes=>30); print "halfago=", $halfago->strftime('%Y-%m-%d-%H-%M-%S %Z'), "\n"; # note comparators are overloaded for DateTime objects print "halfago ", ($halfago>$old?'>':'<='), " old\n";