Simply  Seth
Simply Seth

Reputation: 3506

epoch time comparison bsd / MacOSX

This should be obvious to all but me,

I have a file full of epoch timestamps and I'm trying to get the records from the last 7 days.

So I tried this in my mac:

PAST=$(gdate -d "7 days ago" +%s)
if [ $timeval -gt  $PAST ]; then
  do stuff 
 fi

Example erroneous output:

TS from data, Human fr data, TS from $PAST, Human from $PAST
1419981977690,Tue Jun  9 06 14 50 PST 46967,1421129827,Mon Jan 12 22 17 07 PST 2015
1419400311440,Thu Jan  2 00 17 20 PST 46949,1421129827,Mon Jan 12 22 17 07 PST 2015
1420341489480,Fri Oct 30 06 38 00 PST 46978,1421129827,Mon Jan 12 22 17 07 PST 2015
1421232275040,Thu Jan 22 07 04 00 PST 47007,1421129827,Mon Jan 12 22 17 07 PST 2015

Upvotes: 1

Views: 102

Answers (1)

user149341
user149341

Reputation:

The timestamps in your file are in milliseconds, not seconds. Divide them by 1000.

Upvotes: 2

Related Questions