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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Convert datetime to just date

Author  Topic 

Mondeo
Constraint Violating Yak Guru

287 Posts

Posted - 2007-08-23 : 12:32:15
A have this where clause

WHERE updated >= '2007/16/8'

This gives me all records within the last 7 days - fine.

But I want to exclude records where the updated and created date are the same.

WHERE updated >= '2007/16/8' AND Updated <> Created

This doesn't work, the same records as the first query are returned.

The updated and created columns are both datetime, do I need to specify that I only want to compare the date portion? If so how do I do this?

Thanks

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2007-08-23 : 12:38:36
WHERE updated >= dateadd(dd,DATEDIFF(dd,0,'2007/8/16')
and dateadd(dd,DATEDIFF(dd,0,updated)<> dateadd(dd,DATEDIFF(dd,0,created)

Jim
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-08-23 : 12:55:12
Hopefully UPDATED is always greater than or equal to CREATED. Never less than.

WHERE updated >= '200708016'
and DATEDIFF(dd,created, updated) > 0


but if it is not...

WHERE updated >= '200708016'
and DATEDIFF(dd,created, updated) <> 0


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-08-23 : 14:59:28
You can also use the DateOnly() function here:

http://weblogs.sqlteam.com/jeffs/archive/2007/01/02/56079.aspx

Lots of handy functions for manipulating dates there ...

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page
   

- Advertisement -