user6363065
user6363065

Reputation: 81

Check if time is between two values in SQL

I am trying to get something like below in SQL

if (current time in between 5AM to 3PM )
then print "firsshift"
else (current time in between 5AM to 3PM)
then print "second shift"

Upvotes: 0

Views: 56

Answers (1)

Isaac
Isaac

Reputation: 3363

DECLARE @CurrentTime AS TIME

SET @CurrentTime = GETDATE()

SELECT @CurrentTime AS CurrentTime,
CASE 
    WHEN @CurrentTime BETWEEN '5:00:00' AND '15:00:00' THEN
        'First Shift'
    ELSE
        'Second Shift'
END AS WhichShift

Upvotes: 2

Related Questions