Hari
Hari

Reputation: 3

How to format interval to hours : minutes in pgsql

When we use this query

select '2930:41:51.974223'::interval(0);

Output

 interval  
------------
 2930:41:52

Desired Output

2930:42

I tried

select to_char('2930:41:51.974223'::interval(0),'HH24:MI');

Results:

 to_char 
---------
 2930:41

It won't round 41 to 42 by adding the seconds)

Upvotes: 0

Views: 303

Answers (2)

Vivek S.
Vivek S.

Reputation: 21905

select to_char('2930:41:51.974223' + interval '30','HH24:MI');

or

select to_char('2930:41:51.974223' + interval  '30 seconds','HH24:MI');

Upvotes: 0

klin
klin

Reputation: 121604

Simply add 30 seconds to the interval:

select to_char('2930:41:51.974223'::interval(0)+ '30s','HH24:MI');

 to_char 
---------
 2930:42
(1 row)

Upvotes: 2

Related Questions