0

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?

user3325861
  • 59
  • 1
  • 1
  • 6
  • It would all depend on the database load, whether you use the tools on the DB or in the perl process. There are some good answers below for each. – alexmac Mar 01 '14 at 15:59

4 Answers4

3

SQL that would return the timestamp 24 hours ago.

SELECT UNIX_TIMESTAMP(NOW() - INTERVAL 24 HOUR) 

Now if your timestamp is < the timestamp returned by the above SQL , 24 hours have passed.

2

The best thing is to let the database do the work. See SQL statement to select all rows from previous day for an example.

Community
  • 1
  • 1
choroba
  • 231,213
  • 25
  • 204
  • 289
1

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";
}
Pradeep
  • 3,093
  • 17
  • 21
0

You can use localtime for that.

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($unix_timestamp);
Chankey Pathak
  • 21,187
  • 12
  • 85
  • 133