80

How do I convert the following format to UNIX timestamps?

A value like: 01-02-2015 10:20 PM should be converted to: 1418273999000

I did try to_timestamp function but its not working for me.

0

3 Answers 3

140

If your data is stored in a column called ts, in a table called data, do this:

select extract(epoch from ts) from data
Sign up to request clarification or add additional context in comments.

3 Comments

How fast is it?
Its not slow at all, unnoticable slow down if any. Either way it has to do something to convert the time to something usable, and likely it's stored in something more similar to epoch/unix format as opposed to hh:mi:ss or whatever.
25

To add Joe's answer, you can use date_part, i think it's syntax is clearer than 'extract'.

select date_part('epoch', ts) from data;

Comments

-1

Adding to haoming answer, for UNIX epoch this was my approach. I also added a 180 day interval which can be changed/removed upon requirements.

date_part('epoch', (column_name + INTERVAL '180 day')) * 1000

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.