Sarfaraz Makandar
Sarfaraz Makandar

Reputation: 6733

left() function in PostgreSQL

I need to display only the hours of the time. The following script is my attempt to do the same.

Example:

select left(visittime,2) from records;

Here visittime contains:

10:00:00;

So I need to display only the 10 from it. I have tried by using above script but I am getting an error.

Error:

function left(time without time zone, integer) does not exist

Upvotes: 0

Views: 287

Answers (2)

Joseph B
Joseph B

Reputation: 5669

Another alternative is to use the EXTRACT function, as below:

select extract(hour from visittime) from records;

Reference:

Date/Time Functions and Operators on PostgreSQL Documentation

Upvotes: 3

Clodoaldo Neto
Clodoaldo Neto

Reputation: 125284

select to_char(visittime, 'HH24') from records;

Upvotes: 3

Related Questions