Oracle取某个时间点前后的整半小时的时间点:
需求简述:例如考勤计算中,我们是以0.5小时为单位去计算考勤时数,则需要对上班时间向后取整,下班时间向前取整
例如:上班时间:8:18,按8:30计算;下班时间17:58,按17:30计算。
select sysdate as 当前时间,
trunc(sysdate, 'hh24') +
decode(sign(to_number(to_char(sysdate, 'mi')) - 30), 1, 1 / 48, 0) as early_time,
trunc(sysdate, 'hh24') +
decode(sign(to_number(to_char(sysdate, 'mi')) - 30), 1, 1 / 24, 1 / 48) as later_time
from dual;
拿系统时间做测试,输出结果:

感谢您的阅读,如有错误或不足之处,敬请批评指正!
本文介绍了一种在Oracle数据库中实现考勤时间计算的方法,通过使用特定的SQL语句,可以将时间点精确到半小时的倍数,适用于考勤系统中对上下班时间进行标准化处理的需求。
1206

被折叠的 条评论
为什么被折叠?



