Reputation: 389
Just as we are able to extract the date from timestamps in Postgresql using date(CURRENT_TIMESTAMP)
, I was wondering if there's a equivalent function to extract time. (formatted as hh:mm:ss)
I want to be able to compare a time value, stored in a column with the time datatype (see https://www.postgresql.org/docs/current/datatype-datetime.html), to the current time just using an SQL query.
Any suggestions are most welcome!
Upvotes: 0
Views: 830
Reputation:
You can either use current_time
or casting a timestamp to time: current_timestamp::time
e.g.
where the_time_column >= current_time - interval '6' hour
For details, see Current Date/Time in the Postgres manual
Upvotes: 3