如何检查我当前的时间戳是否在时间范围之间。
ex:我想查看我当前的时间(比如说03:00 PM)是在06:00 PM到07:00 PM之间。
如何在Oracle中查看?
答案 0 :(得分:2)
SELECT CASE
WHEN SYSDATE - TRUNC( SYSDATE ) BETWEEN 17.5/24 AND 18.5/24
THEN 'Is between 17:30 and 18:30'
ELSE 'Not between 17:30 and 18:30'
END
FROM DUAL;
或
SELECT CASE
WHEN SYSDATE BETWEEN TRUNC( SYSDATE ) + INTERVAL '17:30' HOUR TO MINUTE
AND TRUNC( SYSDATE ) + INTERVAL '18:30' HOUR TO MINUTE
THEN 'Is between 17:30 and 18:30'
ELSE 'Not between 17:30 and 18:30'
END
FROM DUAL;
答案 1 :(得分:1)
我会使用字符串进行比较:
select
case when to_char(sysdate, 'HH24:MI') >= '18:00'
and to_char(sysdate, 'HH24:MI') < '19:00' then 'YES' else 'NO'
end as in_time_range
from dual;