Oracle timing comparison
You cannot do
in the instructions
, but you can do a direct comparison with sysdate. If you are doing it this way, it is probably better to use a number rather than relying on implicit conversion. You also don't need extra minutes, etc. Something like,
begin if to_number(to_char(sysdate,'HH24')) <= 15 then -- do something end if; end;
If you want to use minutes by converting it to a string without a colon, you can do a more direct comparison. While the date / time is converted in 24-hour format without additional settings, and in the opposite way, comparing year, month, day, hour, etc. will always be accurate, eg.
begin if to_char(sysdate,'HH24MI') <= '1515' then -- do something end if; end;
However, it is often better to do date comparisons as @cagcowboy just posted before I get there!
source to share