Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Adding 30 mins DateTime

Author  Topic 

CraigMuckleston
Starting Member

6 Posts

Posted - 2007-12-14 : 07:24:27
I am trying to add 30 mins to a datetime stamp so that I can retrieve a list whose datetime is less than or equal to now + 30 mins. I have the following, but it I'm not getting any rows that have a timestamp less than or eqaul to 30 minutes from now...

declare @intMin int

set @intMin = DatePart(mi, DateAdd(mi, 30, @dtmDateTimeExpected))

select fields
from table
where
DatePart(mi, Visit.dtmDateTimeExpected) <=
DatePart(mi, @intMin)
and
DatePart(hh, Visit.dtmDateTimeExpected) <=
DatePart(hh, case when @intMin < DatePart(mi, mDateTimeExpected)
then DatePart(hh, @dtmDateTimeExpected) + 1
else
DatePart(hh, @dtmDateTimeExpected)
end)
and
DatePart(dy, Visit.dtmDateTimeExpected) =
DatePart(dy, @dtmDateTimeExpected)
and
DatePart(mm, Visit.dtmDateTimeExpected) =
DatePart(mm, dtmDateTimeExpected)
and
DatePart(yy, Visit.dtmDateTimeExpected) =
DatePart(yy, dtmDateTimeExpected)

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-12-14 : 07:28:16
One of these

select fields
from table
where datecol<=dateadd(minute,30,getdate())

select fields
from table
where datecol<=dateadd(minute,-30,getdate())

or post some sample data with expected result

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -