Greetings All. I thought this should be really simple using Time::Piece, however I am not getting the result I would expect. As part of a larger script, I just want find if a datetime in a specific format is within the last 30 minutes.
use strict; use warnings; use Time::Piece; my $ctime = Time::Piece->new; my $oldtime = Time::Piece->strptime('Dec 19 17:01:00 2016', '%b %d %T +%Y'); print "The current time is $ctime\n"; print "The old time is $oldtime\n"; my $halfago = $ctime - 1800; print "Half an hour ago is $halfago\n"; if ($oldtime > $halfago) { print "Old time is within a half hour\n"; } else { print "Old time is outside a half hour\n"; }
I ran the script just now, and this is the output:
The current time is Mon Dec 19 17:07:06 2016 The old time is Mon Dec 19 17:01:00 2016 Half an hour ago is Mon Dec 19 16:37:06 2016 Old time is outside a half hour
It doesn't matter what time I set in the script, it always drops down to the else block. I though perhaps I saw something about strptime and GMT, but now I can't find that page again... I think I am probably totally frazzled at this point and am missing something simple. Thanks!
In reply to Simple (I thought) time comparison? by sjessie
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |