Can't extract date from milliseconds epoch postgresql

Viewed 88

I'm querying the database (RedShift) and I have a piece of information stored in epoch MS format. Envision a table along the lines of:

Purchase, date
1, 1620140227019
2, 1620140227045
3, 1620140226573

I need to convert the timestamp to a readable date but I can't make it work with to_timestamp() or extract(). The problem is first with the size of the value (13 digits are not supported). The closest solution I have is

select  to_timestamp(1620140226573/1000, 'SS')

But the result is 0051-05-04 14:57:06. In other words month, date and seconds are correct but the year is wrong.

2 Answers

You can run this query

select to_timestamp(round(1620140227254/1000))
Related