query for calulating between time

Posted by Kavi.Sirius under Sql Server on 6/4/2012 | Points: 10 | Views : 897 | Status : [Member] | Replies : 2
how to find the between time ?

for example
t1=2012-06-01 01:40:00.000 t2= 2012-06-01 02:30:00.000
I should not allow the user to enter time between t1 and t2 dis s if already inserted in db.

Regards
Kavi.n



Responses

Posted by: Jasminej on: 6/4/2012 [Member] Starter | Points: 25

Up
0
Down
Hi
Declare @T1 DATETIME, @T2 DATETIME

Select @T1='2012-06-01 01:40:00.000', @T2= '2012-06-01 02:30:00.000'

If (DateDiff(Minute,@T1, @T2) >0)
Select 'Data already available for this period!' [Status]
Else
Select 'New Data!' [Status]


Kavi.Sirius, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ajay.Kalol on: 6/4/2012 [Member] Starter | Points: 25

Up
0
Down

You need to Check Existing DateTime for Inserted DateTime
If It is Exists then Deny the user to Insert DateTime

Declare @i Int
@i = SELECT COUNT(1) WHERE EnteredTime BETWEEN ExistingTime1 AND ExistingTime2

IF @i > 0
BEGIN
INSERT Statement
END
ELSE
BEGIN
Print 'Date Already Exists'
END

Ajay
ajaypatelfromsanthal.blogspot.in

Kavi.Sirius, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response