17

I am using Athena to query the date stored in a bigInt format. I want to convert it to a friendly timestamp.

I have tried:

from_unixtime(timestamp DIV 1000) AS readableDate

And

to_timestamp((timestamp::bigInt)/1000, 'MM/DD/YYYY HH24:MI:SS') at time zone 'UTC' as readableDate

I am getting errors for both. I am new to AWS. Please help!

3
  • 5
    Did you try from_unixtime(timestamp / 1000)? Aug 22, 2018 at 21:09
  • @PiotrFindeisen you should add this as a proper answer! It just saved me!
    – Tom Dalton
    Sep 30, 2019 at 14:43
  • @TomDalton at your service! Oct 1, 2019 at 6:50

1 Answer 1

31

Assuming you have t value representing "Java timestamp" (milliseconds since epoch), you can use from_unixtime:

from_unixtime(timestamp / 1000e0)

If you want to discard the millisecond component of your timestamp value, this will do this:

from_unixtime(timestamp / 1000)
1
  • 1
    from_unixtime(timestamp / 1000) worked for me when looking at WAF logs. Mar 16, 2022 at 11:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.