There are two ways to accomplish this goal. If you are running SQL 2008 or later, the simplest and the fastest solution is just to convert to the DATE datatype. If you are running SQL 2005 or earlier, you have to do a bit more funky dance:
Code:
DECLARE @a DATETIME = GetDate()
, @b DATETIME
, @i INT = 0
, @j INT = 0
, @limit INT = 10000000
, @d1 DATETIME2
, @d2 DATETIME2
, @d3 DATETIME2
SET @d1 = GetDate()
WHILE @i < @limit
SELECT @i += 1, @b = Cast(@a AS DATE)
SET @d2 = GetDate()
WHILE @j < @limit
SELECT @j += 1, @b = DateAdd(day, 0, DateDiff(day, 0, @a))
SET @d3 = GetDate()
SELECT @a, @b
, DateDiff(ms, @d1, @d2)
, DateDiff(ms, @d2, @d3)
, DateDiff(ms, @d2, @d3) - DateDiff(ms, @d1, @d2)
-PatP