Time difference in seconds

Xi Vix picture Xi Vix · Feb 3, 2012 · Viewed 37.1k times · Source

In a Perl program I have a variable containing date / time in this format:

Feb 3 12:03:20  

I need to determine if that date is more than x seconds old (based on current time), even if this occurs over midnight (e.g. Feb 3 23:59:00 with current time = Feb 4 00:00:30).

The perl date / time information I've found is mind-boggling. Near as I can tell I need to use Date::Calc, but I am not finding a seconds-delta. Thanks :)

Answer

Sjoerd Linders picture Sjoerd Linders · Jun 14, 2013
#!/usr/bin/perl

$Start = time();
sleep 3;
$End = time();
$Diff = $End - $Start;

print "Start ".$Start."\n";
print "End ".$End."\n";
print "Diff ".$Diff."\n";

This is a simple way to find the time difference in seconds.