In my postgresql I have the following table:
Name: mytable
---
id INT PRIMARY KEY,
time TIME WITHOUT TIME ZONE
And I select some info:
select id,time from mytable;
But I want the time to be formated without seconds. How I can do this?
In my postgresql I have the following table:
Name: mytable
---
id INT PRIMARY KEY,
time TIME WITHOUT TIME ZONE
And I select some info:
select id,time from mytable;
But I want the time to be formated without seconds. How I can do this?
2
Answers
According to postgresql documentation you need to use the
to_char
function.In your case you'll need to do:
OR
This is applicable to all postgresql versions. I tested it on Postgresql 11.
As answered by Dimitrios Desyllas , using "to_char" is the best way.
Alternatively, the same can also by achieved by "date_trunc" function. It truncates the value to the nearest minute.
This can be done as:
Another way of achieving this is by "Substring", this can be done as: