I have the following field in my table:
VISIT_DATE TIMESTAMP(0)
And it is holding time like that:
2022-01-13 11:04:15
Could someone tell me is it possible to cut off that seconds? I really don't need them. I want to hold time in the following format:
2022-01-13 11:04
CodePudding user response:
Either truncate the timestamp by minutes using date_trunc
, which will return a timestamp without seconds, or use to_char
if it is only about formatting the output:
SELECT date_trunc('minute',VISIT_DATE) FROM t;
SELECT to_char(VISIT_DATE,'yyyy-mm-dd hh24:mi') FROM t;
Demo:
Using date_trunc
(result as timestamp):
SELECT date_trunc('minute','2022-01-13 11:04:15'::timestamp);
date_trunc
---------------------
2022-01-13 11:04:00
(1 Zeile)
Using to_char
(result as text):
SELECT to_char('2022-01-13 11:04:15'::timestamp,'yyyy-mm-dd hh24:mi');
to_char
------------------
2022-01-13 11:04
CodePudding user response:
Try this SELECT FORMAT(VISIT_DATE, 'yyyy-mm-dd HH:mm')