hi guys, I have a field named 'CreatedDate' in table.It contain value as 2009-12-07 11:02:20.890.My search parameter is createddate.Parameter contains value as 2009-12-07.My parameter contains only datepart.If my parameter contains only 2009-12-07 its not giving result.Only when time is included its giving result. My query is Select * from STD_Enquiry where CreatedDate='2009-12-07 Can anybody give approppriate query to get the result?
+4
A:
Compare only on the date portion (without time):
WHERE DateColumn >= DATEADD(day, DATEDIFF(day, 0, @SomeDateParam), 0)
Mitch Wheat
2009-12-08 04:21:25
Yes. But if you include an explanation (or a link to one) on *why* this works, it'd help him more.
Philip Kelley
2009-12-08 04:26:35
@Phillip, ok thanks: http://mitch-wheat.blogspot.com/2007/05/sql-server-compare-date-part-of.html
Mitch Wheat
2009-12-08 05:07:37
And this too: http://stackoverflow.com/questions/133081/most-efficient-way-in-sql-server-to-get-date-from-datetime
gbn
2009-12-08 06:03:20
@gn: nice ref. to timings of the techniques.
Mitch Wheat
2009-12-08 06:17:32
A:
Try this:
Select * from STD_Enquiry where CreatedDate like '2009-12-07%'
Dumb Guy
2009-12-08 04:22:09
A:
Use this query to comapare only date
Select * from STD_Enquiry where to_char(CreatedDate,'mmddyyyy') = '09102007'
Vijay Sarathi
2009-12-08 05:36:21
A:
Select * from Table where CreatedDate= ''Datepart(yyyy, CreatedDate) + '-' + Datepart(mm,CreatedDate) + '-' + Datepart(DD,CreatedDate)''
MSH
2009-12-08 06:09:43