perldatetimeelapsed

Perl: how to know if 24hrs have passed?


I have a timestamp field on a mysql table , i want to know if that timestamp is 24hrs old or more. What would be the best way to do that in Perl?


Solution

  • By timestamp I am assuming it's Unix timestamp, i.e. seconds since epoch.

    my $ts       = 1393662619;
    my $day_24hr = 24 * 60 * 60;    ## seconds in 24 hrs
    
    my $prev_time = time() - $day_24hr;    ## 24hours ago
    
    if ( $ts < $prev_time ) {
        print "timestamp is 24 hour old";
    }