Postgres convert time without minutes in format

Postgres convert time without minutes in format



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)


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



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





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






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế