Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract hour from query in postgres

People also ask

How do I get system time in PostgreSQL?

The PostgreSQL function CURRENT_TIME returns the current time and time zone offset of the machine on which PostgreSQL is running. It is given as a value in the 'hh:mm:ss. nnnnnn+/-tz' format.

What is extract in PostgreSQL?

PostgreSQL EXTRACT() function The extract function() is used to retrieves subfields such as year or hour from date/time values. The source must be a value expression of type timestamp, time, or interval. The field is an identifier or string that selects what field to be extracted from the source value.


The following should work

select extract(hour from observationtime) from smartvakt_device_report

SELECT to_char(now(), 'HH24:MI:SS')  hour_minute_second

The word timezone is redundant (read: wrong). You just need to give the column's name. E.g.:

db=> select extract(hour from observationtime) from smartvakt_device_report;

 date_part 
-----------
        19
(1 row)