Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't extract time from timestamp Postgres

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?

like image 927
Hangon Avatar asked Aug 24 '17 15:08

Hangon


2 Answers

select '2000-01-01 01:12:00'::timestamp::time
like image 81
Clodoaldo Neto Avatar answered Nov 19 '22 21:11

Clodoaldo Neto


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

like image 37
Vao Tsun Avatar answered Nov 19 '22 22:11

Vao Tsun