Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redshift convert dates to unix timestamps

I have a column of dates in a Redshift table. I would like the output to be in the form of unix timestamps. Essentially, I want the opposite of this question: How to convert epoch to datetime redshift?

Is there a way to do this?

like image 937
user1742188 Avatar asked Jan 04 '23 21:01

user1742188


2 Answers

You can just use EPOCH with DATE_PART.

select date_part(epoch, date_column)
from tbl  

From the documentation

The Amazon Redshift implementation of EPOCH is relative to 1970-01-01 00:00:00.000000 independent of the time zone where the server resides. You might need to offset the results by the difference in hours depending on the time zone where the server is located.

like image 56
Vamsi Prabhala Avatar answered Jan 08 '23 06:01

Vamsi Prabhala


Date_part is dead. Use extract() now --

SELECT extract(epoch from CURRENT_DATE)
like image 24
XaxD Avatar answered Jan 08 '23 06:01

XaxD