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)
 select on dates

Author  Topic 

helixpoint
Constraint Violating Yak Guru

291 Posts

Posted - 2010-11-05 : 09:06:33
The field is a datetime fieldexample "2010-09-13 15:27:30.327"

How do I query on the datetime field when I am passing a date like "09/13/2010"

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

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-11-05 : 09:18:12
SELECT * FROM YourTable WHERE DATEADD(day, 0, DATEDIFF(day, 0, dateField)) = '9/13/2010'

but I strongly recommend using unambiguous date format:

SELECT * FROM YourTable WHERE DATEADD(day, 0, DATEDIFF(day, 0, dateField)) = '20100913'
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-11-05 : 09:20:31
where datecol >= convert(datetime,'09/13/2010',101)
and datecol < dateadd(day,1,convert(datetime,'09/13/2010',101))


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

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-11-08 : 05:31:42
More on querying dates
http://beyondrelational.com/blogs/madhivanan/archive/2010/06/21/understanding-datetime-column-part-iii.aspx

Madhivanan

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

- Advertisement -