Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon Athena: Convert bigint timestamp to readable timestamp

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!

like image 410
noobeerp Avatar asked Aug 22 '18 20:08

noobeerp


People also ask

How do you change timestamp in Athena?

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.

What data format does Amazon Athena support?

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.

How do I get the timestamp from a Presto date?

You can convert timestamp to date with cast(col as date) or date(col) .


1 Answers

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)
like image 131
Piotr Findeisen Avatar answered Oct 14 '22 15:10

Piotr Findeisen