user42348
user42348

Reputation: 4319

How to get date from datetime in sql

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?

Upvotes: 0

Views: 630

Answers (4)

MSH
MSH

Reputation: 11

Select * from Table where CreatedDate= ''Datepart(yyyy, CreatedDate) + '-' + Datepart(mm,CreatedDate) + '-' + Datepart(DD,CreatedDate)''

Upvotes: 0

Vijay
Vijay

Reputation: 67211

Use this query to comapare only date

Select * from STD_Enquiry where to_char(CreatedDate,'mmddyyyy') = '09102007'

Upvotes: 0

Dumb Guy
Dumb Guy

Reputation: 3446

Try this:

Select * from STD_Enquiry where CreatedDate like '2009-12-07%'

Upvotes: 0

Mitch Wheat
Mitch Wheat

Reputation: 300489

Compare only on the date portion (without time):

WHERE DateColumn >= DATEADD(day, DATEDIFF(day, 0, @SomeDateParam), 0)

Upvotes: 5

Related Questions