Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract Hours and Minutes (from Date) as a number in Oracle?

What I did:

SELECT TO_CHAR(SYSDATE, 'HH24:MI') FROM dual;

What i got:

13:30

What I want :

13.50

I also tried the EXTRACT function then summed hours and minutes but still not working.

like image 448
dwalker Avatar asked Nov 26 '25 12:11

dwalker


2 Answers

If you want the actual time (not just hours and minutes), you can do:

select ( sysdate - trunc(sysdate) ) * 24, sysdate
from dual;

If you just want just hours and minutes:

select extract(hour from current_timestamp) + extract(minute from current_timestamp) / 60
from dual
like image 107
Gordon Linoff Avatar answered Nov 28 '25 02:11

Gordon Linoff


If you want the time-of-day (hours, minutes and seconds) expressed in fractional hours, then you can use

( sysdate - trunc(sysdate) ) * 24

as Gordon has shown already.

If you want to truncate the seconds and just convert the hour and minute into hours, then you can use

( trunc(sysdate, 'mm') - trunc(sysdate) ) * 24

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!