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
 DateTime

Author  Topic 

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2012-04-23 : 10:15:32
My date datatype is DATETIME.

MyDate
2012-04-26 00:00:00.000

How can I select a list of this date 2012-04-26 without the time using dateadd?

It return 0 records when i run this:
select * from tableName where
mydate = DATEADD(Day,3,Cast(getdate() as DateTime))

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-04-23 : 10:22:50
dateadd(day, datediff(day, 0, getdate())

or if you are using SQL 2008

convert(date, getdate())


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2012-04-23 : 10:24:33
im using sql 2008

i get this error using convert

Type date is not a defined system type
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-04-23 : 10:27:39
your comp level is probably not 100


SELECT compatibility_level
FROM sys.databases
WHERE name = '<DB NAME>';


use the dateadd(datediff()) method


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2012-04-23 : 10:40:15
is 90

got it.thanks!
Go to Top of Page
   

- Advertisement -