简体   繁体   中英

Round up SYSDATE just but its HOUR. SQL ORACLE

Any ideas how to round up SYSDATE.

For example, sysdate right now is 11.31 , and i want it to round up to 12.00 , but i expect the output to be just 12 , and if the Sysdate is 11.29 , the output is 11 .

Thanks

Use ROUND function and after that TO_CHAR .

select to_char(round(to_date('11:31','hh24:mi'), 'HH'), 'HH24') from dual

-> 12

select to_char(round(to_date('11:29','hh24:mi'), 'HH'), 'HH24') from dual

-> 11
ROUND((SYSDATE-TRUNC(SYSDATE))*24)

Explanation: TRUNC without 2nd parameter makes the 00:00:00 time of the current date. By subtraction we get the difference (in days), then scale it to hours and round.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM