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!
Athena requires the Java TIMESTAMP format. Use Presto's date and time function or casting to convert the STRING to TIMESTAMP in the query filter condition. For more information, see Date and time functions and operators in the Presto documentation.
Q: What data formats does Amazon Athena support? Amazon Athena supports a wide variety of data formats like CSV, TSV, JSON, or Textfiles and also supports open source columnar formats such as Apache ORC and Apache Parquet. Athena also supports compressed data in Snappy, Zlib, LZO, and GZIP formats.
You can convert timestamp to date with cast(col as date) or date(col) .
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With