1

I expected this to be easier than it is, but I have a table with times in it in a format like:

11:35:00 
12:02:00 
13:04:00

I need to return those times so it only shows:

11:35
12:02
13:04

Every solution I can find online says to use

date_trunc('minute', time_here)

That just returns the time in the same seconds format that it is already in. I want the seconds completely removed from the format. Any way to just change it to HH:MM format? Thanks

1 Answer 1

3

If this is for display purposes, with for example the following definition:

create table t1 (tt timestamp);
insert into t1 values ('2018-08-24 12:10:00');
insert into t1 values ('2018-08-24 11:02:00');
insert into t1 values ('2018-08-24 13:00:30');

The the following:

select to_char(tt, 'HH24:MI') from t1;

will produce:

to_char
12:20
11:02
13:00

date_trunc leaves the data as a timestamp and a select on a timestamp will display in the usual format. Explicit conversion to char (as with to_char) allows different layouts.
Documentation on all different formatting options for this can be found here

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! For my purpose I only needed to do the "select to_char(tt, 'HH24:MI')" part of the answer, but that works.

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.