TIme Difference

Database
Enthusiast

TIme Difference

Hello All,

THe below query is to find the difference between Previous Hour Time - Minutes to get the beginning of the previous hour.

SEL CAST(CAST(CURRENT_TIME AS FORMAT 'HH:MI') AS CHAR(8)) - EXTRACT(MINUTE FROM(CAST(CAST(CURRENT_TIME AS FORMAT 'MI:SS') AS CHAR(5)))) (TITLE 'OUTPUT')

I am getting the output in integers as given below

OUTPUT

1,600.00

I want the output as 16:00.

 

Like DATE Function saved in integer internally, is time also saved in integer?

Thanks

Jugal

Tags (1)
2 REPLIES
Senior Apprentice

Re: TIme Difference

Hi Jugal,

you cast current_time to a CHARs and then substract two CHARs, what do you expect?

If you want the result to be a CHAR:

CAST(CAST(CURRENT_TIME AS FORMAT 'hh:') AS CHAR(3)) || '00'

If you want a TIME:

TIME '00:00:00' + (INTERVAL '01' HOUR * EXTRACT(HOUR FROM CURRENT_TIME))
Enthusiast

Re: TIme Difference

Thanks Dieter.. :)..