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
 datediff and convert

Author  Topic 

bill_
Starting Member

38 Posts

Posted - 2009-04-20 : 10:39:43
Hello,
I am trying to query for records with dates that are within a year of each other. Date1 is a datetime type and the date2 is a string like 20081225. When I try

select * from table1 where datediff(year,date1,convert(datetime,date2,112))<1

the number comes out too high.

What am I doing wrong?
Thanks

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-04-20 : 11:30:53
See here how DATEDIFF works
http://www.sqlteam.com/article/datediff-function-demystified

Use
datediff(year, date1, date2) = 0




E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -