10

Hi im trying to extract time from a timestamp in Postgres

SELECT extract(time from '2000-01-01 01:12:00'::timestamp)

Result should be: 01:12:00

It looks like that time is not a valid argument for extract. Is that right?

0

2 Answers 2

20
select '2000-01-01 01:12:00'::timestamp::time
Sign up to request clarification or add additional context in comments.

Comments

11

Try this:

s=# SELECT cast ('2000-01-01 01:12:00'::timestamp as time);
   time
----------
 01:12:00
(1 row)

doesn't extract - then, you might want to use cast.

and yes - https://www.postgresql.org/docs/current/static/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT

time is not a valid aprt

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.