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'.
Asked
Active
Viewed 5.1k times
3 Answers
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
-
cast((from_unixtime(unixtime)) as date) this worked for me. – Siddhant Saxena May 31 '18 at 06:34
-
the unixtime is in ms as per the question, hence we should be using `cast(from_unixtime(unixtime/1000) as date)` – Sairam Cherupally Apr 12 '23 at 08:09
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

kickstart530
- 9
- 3
-
1Your 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
-
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