0

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
2

2 Answers 2

3
select to_char(visittime, 'HH24') from records;
Sign up to request clarification or add additional context in comments.

Comments

3

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

1 Comment

You're welcome! The documentation on the website reference has a lot of information + examples for each function :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.