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
 How to compare a certain part of a cell?

Author  Topic 

rocco2008
Yak Posting Veteran

63 Posts

Posted - 2009-03-27 : 11:12:34
Hello,

I have a little problem. I have an event which received a timestamp at the moment where it was created. The timestamp looks like this: 2008-12-08 07:31:09.600. Once the event gets modified, I get a second timestamp.

Now I would like to create a SELECT Statement, where one condition is, that the date on which the event was created is equal to the date the timestamp was modified, but I have no clue how to seperate the date-part of the timestamp. It should look something like this:

SELECT x FROM table
WHERE [Date from Creation-Timestamp] = [Date from Modifying-Timestamp]

Many thanks in advance,

Rocky

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-03-27 : 11:23:59
[code]SELECT x FROM table
WHERE dateadd(dd,datediff(dd,0,[Date from Creation-Timestamp]),0) = dateadd(dd,datediff(dd,0,[Date from Modifying-Timestamp]),0)[/code]
Go to Top of Page

rocco2008
Yak Posting Veteran

63 Posts

Posted - 2009-03-27 : 12:14:42
Awesome Thanks!
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-03-27 : 12:38:09
np
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-28 : 03:44:12
if you've any index on any of date fields then use
SELECT x FROM table
WHERE [Date from Creation-Timestamp] >= dateadd(dd,datediff(dd,0,[Date from Modifying-Timestamp]),0)
AND [Date from Creation-Timestamp] < dateadd(dd,datediff(dd,0,[Date from Modifying-Timestamp]),1)

or

SELECT x FROM table
WHERE [Date from Modifying-Timestamp] >= dateadd(dd,datediff(dd,0,[Date from Creation-Timestamp]),0)
AND [Date from Modifying-Timestamp] < dateadd(dd,datediff(dd,0, [Date from Creation-Timestamp]),1)
Go to Top of Page
   

- Advertisement -