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;
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/