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
 General SQL Server Forums
 New to SQL Server Programming
 search date portion of datetime in where clause

Author  Topic 

tpiazza55
Posting Yak Master

162 Posts

Posted - 2012-06-04 : 17:10:35
I have a indexed column orderdate which is a datetime

I am passed a datetime string in the form of 01062012181117.

I only want to compare the date portion. How so i do this in a where clause

where OrderDate (date portion only) = '01062012'

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-06-04 : 17:54:18
WHERE OrderDate = DATEADD(D, 0, DATEDIFF(D, 0, YourColumn))

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tpiazza55
Posting Yak Master

162 Posts

Posted - 2012-06-04 : 18:10:39
so that will only check the date portion of the orderdate column?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-06-04 : 18:30:08
Yes. Please try it out.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tpiazza55
Posting Yak Master

162 Posts

Posted - 2012-06-04 : 18:59:43
how you handle one issue

date is sent in ddmmyyyy

datebase is in mmddyyyy
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-06-04 : 19:03:45
I already answered it in your other thread.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -