Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a table CA with this field: ID_CA, CA_NAME, TimeStart, TimeEnd
I want to set CA_NAME is 'DAY' into CA if TimeStart and TimeEnd between '6:00:00 P.M' and '5:59:59 A.M', CA_NAME is 'NIGHT' if TimeStart and TimeEnd between '6:00:00 A.M' and '5:59:59 P.M'.
I try but no luck. Thanks you!

SQL
Declare @TimeStamp Datetime, @Result int
If @TimeStamp in ('6:00:00 P.M' and '5.59.59 A.M') ==> Return @Result = 1 (It's mean true)
else return Result = 0 (It's mean flase)


Then, i can use this function to detemine DAY or NIGHT.
Thanks You !
Posted
Updated 21-May-15 21:11pm
v4
Comments
RossMW 21-May-15 23:40pm    
What field types are TimeStart and TimeEnd fields?
huy cao 22-May-15 0:08am    
TimeStart, TimeEnd are Datetime. Sorry, i'm forget it !
Thank you!
King Fisher 22-May-15 0:42am    
just post What you have tried?
huy cao 22-May-15 3:02am    
Yeah ! I've posted it below

1 solution

Use DatePart function[^] to get the hour component and compare that to your border values:
SQL
select case when datepart(hour, @TimeStamp) >= 6 and datepart(hour, @TimeStamp) < 18 then 'Day' else 'Night' end
 
Share this answer
 
Comments
huy cao 22-May-15 20:33pm    
Thank you. it's look working good !

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900