16

I have timestamps stored in time since epoch (ms) and I would like to query and display results using a date formatted like 'yyyy-mm-dd'.

deltap
  • 4,176
  • 7
  • 26
  • 35

3 Answers3

35

cast(from_unixtime(unixtime) as date)

See https://prestodb.io/docs/current/functions/datetime.html for more datetime functions.

Christina Foley
  • 691
  • 5
  • 6
0

as you mentioned epoc(ms) division by 1000 would convert it to seconds.

date(from_unixtime(min(ts)/1000))

This helped me my epoch time is saved as BigInt and stored to be accurate to milliseconds.

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 19 '21 at 08:27
  • https://stackoverflow.com/editing-help – Yunnosch Oct 19 '21 at 08:39
0

Use following to get the answer in YYYY-MM-DD format

format_datetime(from_unixtime(unixtime), 'Y-MM-dd')

Example:

format_datetime(from_unixtime(1664582792), 'Y-MM-dd')

Output --> 2022-10-01

Using cast as date as follows

cast(from_unixtime(1664582792) as date)

will give output as

2022-10-01 00:00:00.000
Vijayant
  • 612
  • 2
  • 6
  • 17