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)
 subtracting datetime??

Author  Topic 

helixpoint
Constraint Violating Yak Guru

291 Posts

Posted - 2009-02-03 : 14:16:49
I have a smaldatetime field in my table. I need to do a select to see if that date is < 10 minutes from the current date. How do I do this?

Dave
Helixpoint Web Development
http://www.helixpoint.com

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-02-03 : 14:46:16
Only an approach, but it must be something like this:

select * from table
where yourColumn between dateadd(minute,-10,getdate()) and getdate()



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

helixpoint
Constraint Violating Yak Guru

291 Posts

Posted - 2009-02-03 : 14:58:02
Does that not look for a 10 minute window?

Dave
Helixpoint Web Development
http://www.helixpoint.com
Go to Top of Page

revdnrdy
Posting Yak Master

220 Posts

Posted - 2009-02-03 : 15:29:33
Hello;

Here is a code snippet from a query where I look for the last 2 days from a column called date_time.

You could modify it to reflect minutes (similar to webfreds post).
[CODE]
WHERE date_time > DATEADD(day, DATEDIFF(day, 0, GETDATE())-2,0)
[/CODE]
What it does is looks back over the last 2 days (hence the -2)

Hope that helps

r&r
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-02-03 : 16:27:27
quote:
Originally posted by helixpoint

Does that not look for a 10 minute window?

Dave
Helixpoint Web Development
http://www.helixpoint.com


Yes!
I think I don't understand what you want - sorry.

Webfred


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -