W D
asked on
Comparison time portion of date/time field
Hi,
I need to compare the time portion of a date time field so that I create identify which employee shift it falls into. I have the following SQL:
SELECT
lo.order_proc_id
,CASE
WHEN To_Date(to_char(lo.end_pro cedure_tim e,'hh24:mi ')) >= '08:00' AND
To_Date(to_char(lo.end_pro cedure_tim e,'hh24:mi ')) <= '16:30' THEN '8to4'
WHEN To_Date(to_char(lo.end_pro cedure_tim e,'hh24:mi ')) > '16:30' AND
To_Date(to_char(lo.end_pro cedure_tim e,'hh24:mi ')) <= '24:00' THEN '4-30toMidnight'
WHEN To_Date(to_char(lo.end_pro cedure_tim e,'hh24:mi ')) > '24:00' AND
To_Date(to_char(lo.end_pro cedure_tim e,'hh24:mi ')) <= '08:00' THEN 'MidnightTo8'
ELSE NULL
END AS shift_time
FROM lab_orders lo
I get an error message stating "Not a valid month". How do I fix this?
Many thanks in advance for your review!
I need to compare the time portion of a date time field so that I create identify which employee shift it falls into. I have the following SQL:
SELECT
lo.order_proc_id
,CASE
WHEN To_Date(to_char(lo.end_pro
To_Date(to_char(lo.end_pro
WHEN To_Date(to_char(lo.end_pro
To_Date(to_char(lo.end_pro
WHEN To_Date(to_char(lo.end_pro
To_Date(to_char(lo.end_pro
ELSE NULL
END AS shift_time
FROM lab_orders lo
I get an error message stating "Not a valid month". How do I fix this?
Many thanks in advance for your review!
ASKER
Or, would one not want to use to_char because applying comparison operands on strings may give incorrect results?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I like both of these - just tried them and they both work.
Many thanks for your prompt replies!
Many thanks for your prompt replies!
ASKER