datetime - SQL Server 2012 Time Range Check? -


what smart way determine if current time between 59th minute of hour , first minute of next hour, using pure tsql on mssql 2012?

i not want cut off time "now", want cut off date , time calculation.

this gets me kind of close : datepart time between (instead of convert date) not since need calculate based on current time , not table values.

the following might illustrate if server in "the bad time" , should return value of '1'

14:58:59 ,  should not considered in "bad time" 14:59:00 ,  should considered in "bad time" 14:59:04 ,  should considered in "bad time" 14:59:57 ,  should considered in "bad time" 15:00:02 ,  should considered in "bad time" 15:01:26 ,  should not considered in "bad time" 15:02:00 ,  should not considered in "bad time" 15:02:01 ,  should not considered in "bad time" 

thanks.

edit:

this code works, sure can done more efficiently. recommendations welcomed. again.

declare @now time = ( select cast( sysutcdatetime() time  )) declare @floor time = ( select dateadd( minute , 59 , ( dateadd(hour,datediff(hour,0,@now),0) ) ) ) declare @ceiling time =(  select dateadd( minute , 2 , @floor ) ) if ( @now > @floor , @now < @ceiling ) begin     select 1 bit end select @now , @floor , @ceiling 

please replace @dt required:

declare @dt datetime = '20130419 21:59:01'  select case when datepart(minute, @dt) in (59,0)             'minute between 59 , 1'             else 'minute not between 59 , 1'        end myminute 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -