Spur
asked on
Case statement based on hour in timestamp
I have a timestamp with date and time in it. I want to assign a value to a record which depends on the time of day but the date is irrelevant. I need to write a case statement something like this:
case when (start time between 10 pm and 6 am) and (end time - start time is > 60) then do this
when end time - start time > 20 then do this
else do this end
I don't know the syntax to evaluate a timestamp which only looks at the hour.
case when (start time between 10 pm and 6 am) and (end time - start time is > 60) then do this
when end time - start time > 20 then do this
else do this end
I don't know the syntax to evaluate a timestamp which only looks at the hour.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Oops, I was thinking minutes for the 60 and 20 conditions. Change that from 'mi' to 'hh' to use hours instead. Though perhaps you meant for that to be minutes...
ASKER
Giving it a try now, thanks icoehoorn!
Just noticed my enddate and startdate may be backwards also.
ASKER
Thanks, worked great!
ASKER
That part is easy, it is the datepart function I had never used or known about :) Works like a charm, Thanks jcoehoorn