Link to home
Start Free TrialLog in
Avatar of Spur
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.
ASKER CERTIFIED SOLUTION
Avatar of Joel Coehoorn
Joel Coehoorn
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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...
Avatar of Spur
Spur

ASKER

Giving it a try now, thanks icoehoorn!
Just noticed my enddate and startdate may be backwards also.
Avatar of Spur

ASKER

Thanks, worked great!
Avatar of Spur

ASKER

That part is easy, it is the datepart function I had never used or known about :) Works like a charm, Thanks jcoehoorn