user3583912
user3583912

Reputation: 1322

How to exclude between times in T-Sql?

I got below table, I want to exclude between times?

declare @t table (id int, name varchar(50), starttime time(3),endtime time(3))
insert into @t
        ( id, name, starttime, endtime )
values ( 1,'Steve','00:00:00.000','23:59:59.999')
,( 2,'Steve','03:00:00.000','04:00:00.000')
,( 3,'Steve','00:00:00.000','23:59:59.999')
,( 4,'Steve','09:30:00.000','11:30:00.000')

if current time is '03:10:00.000' then I want exclude between time,

1,'Steve','00:00:00.000','23:59:59.999'
3,'Steve','00:00:00.000','23:59:59.999'
4,'Steve','09:30:00.000','11:30:00.000'

any help? Thanks

Upvotes: 1

Views: 57

Answers (1)

diiN__________
diiN__________

Reputation: 7666

Try this (assumed you have a time-variable named currenttime):

SELECT id, name, starttime, endtime
FROM @t
WHERE starttime > currenttime OR endtime < currentTime

Upvotes: 3

Related Questions