Re: Time Comparison Easier Than I'm Making them
- From: rob.dixon@xxxxxxx (Rob Dixon)
- Date: Wed, 28 Nov 2007 22:02:08 +0000
Mathew Snyder wrote:
>
I've got an application which uses the format yyyy-mm-dd hh:mm:ss for its
timestamping. I'm trying to determine if the time a record was created was 5 or
more minutes before the time the script runs. Using DateTime->now I get a
timestamp of yyyy-mm-ddThh:mm:ss. I have no clue what the 'T' represents.
All I'm trying to do is take the hh:mm:ss portion of each timestamp and find the
difference yet I'm pulling my hair out trying to find the solution. Can someone
please just point me to what I can use? I'll figure it out from there.
Here's a little subroutine that will return the number of seconds since
the date stamp string passed to it. It ignores the date part of the
stamp and assumes that the time part is somewhere within the preceding
24 hours. Obviously you would call it as
if (seconds_since($stamp) >= 300) {
:
}
HTH,
Rob
use strict;
use warnings;
sub seconds_since {
my $stamp = shift;
my @stamp = $stamp =~ /\d+/g;
splice @stamp, 0, -3;
my @time = reverse localtime;
splice @time, 0, -3;
my $diff = 0;
while (@time) {
$diff = $diff * 60 + shift(@time) - shift(@stamp);
}
$diff += 24 * 60 * 60 if $diff < 0;
return $diff;
}
.
- References:
- Time Comparison Easier Than I'm Making them
- From: Mathew Snyder
- Time Comparison Easier Than I'm Making them
- Prev by Date: Re: fixed list combinatorics
- Next by Date: Re: Extracting one record from multiple-records textfile
- Previous by thread: Re: Time Comparison Easier Than I'm Making them
- Next by thread: Comparing Regular Expression in Perl vs Python
- Index(es):