The script below works well enough for my liking, but I was wondering if there was an easier way to go about this. I have a saved time which I am subtracting from time() to see how long ago (in seconds) the event happened. From that, I tried to calculate into minutes, then into hours, then into days. I was also wondering if there was a more percise way of going about this.
This is setup to calculate minutes UNTIL it's greater than 60, then automatically calculate hours. How can I make it calculate hours and minutes at the same time? And how could I get it so I could see how many days and hours it was? (I don't mean if it was 27 hours ago that the script would say 1 day(s) 27 hour(s), I'd want it to say 1 day(s) 3 hour(s)).
my $time=time;
my $elapsed = $time - $oldtime;
if ($elapsed < "60") {
print "<td><center>< 1 min</center></td></tr>\n";
}
elsif ($elapsed > "60") {
my $newelapsed = $elapsed / 60;
my $elapsed2 = substr( $newelapsed, 0, 2 );
print "<td><center>$elapsed2 min(s)</center></td></tr>\n";
}
elsif ($elapsed > "3600") {
my $newelapsed = $elapsed / (60*60);
my $elapsed2 = substr( $newelapsed, 0, 2 );
print "<td><center>$elapsed2 hour(s)</center></td></tr>\n";
}
elsif ($elapsed > "43200") {
my $newelapsed = $elapsed / (60*60);
my $elapsed2 = substr( $newelapsed, 0, 2 );
print "<td><center>$elapsed2 day(s)</center></td></tr>\n";
}
}
Any suggestions would be very grateful.