0

I have table:

CREATE TABLE B(
...
date1 TIMESTAMP(6),
date2 TIMESTAMP(6),
...);

and I want to get hours between two timestamps. So I run query:

SELECT (date1 - date2)*24 from B;

Result looks like this: +000000024 00:00:00.000000 but I want something like 24:00. How I can format the query? Thanks

GoobyPrs
  • 585
  • 2
  • 7
  • 15

2 Answers2

2
SELECT to_char((date1 - date2)*24,'HH24:MI') from B;
valentin
  • 3,498
  • 15
  • 23
0

Just use a subquery to extract the hours from the expression

SELECT  extract( hour from x) hours FROM
(SELECT (date1 - date2)x FROM B)
Mihai
  • 26,325
  • 7
  • 66
  • 81