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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 select on dates
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Constraint Violating Yak Guru

291 Posts

Posted - 11/05/2010 :  09:06:33  Show Profile  Reply with Quote
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"

Helixpoint Web Development


5072 Posts

Posted - 11/05/2010 :  09:18:12  Show Profile  Visit russell's Homepage  Reply with Quote
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

Flowing Fount of Yak Knowledge

8781 Posts

Posted - 11/05/2010 :  09:20:31  Show Profile  Visit webfred's Homepage  Reply with Quote
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

Premature Yak Congratulator

22864 Posts

Posted - 11/08/2010 :  05:31:42  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
More on querying dates


Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000