4

I've got a column of type date with the following value format: YYYY-MM-DD (eg. 2018年08月03日). I want to get the unix timestamp equivalent of the dates, but without the timezone.

F.e. the date 2018年08月03日 should equal 1533254400 (as of calculated here).

I've tried to_timestamp(my_date_column, 'YYYY-MM-DD') but it returns error function to_timestamp(date, unknown) does not exist. I've tried adding different variations of ::timestamp... at the end of the function call, but to no avail.

Currently I do the timestamp conversion in the application layer, but I'd like to dedicate that job to the database.

Colin 't Hart
9,51015 gold badges37 silver badges44 bronze badges
asked Sep 5, 2018 at 14:23
1
  • to_timestamp does the opposite (Epoch to datetime/timestamp). Commented Sep 5, 2018 at 14:35

1 Answer 1

7

Alright... after a change in my approach, I decided to try to "extract" data instead of convert. Turned out there's the oh-so convenient function extract in Postgres, which does exactly what I want.

extract(EPOCH from my_date_column) as date_timestamp

Here is a more detailed explanation.

answered Sep 5, 2018 at 14:32
1

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.