Home Forums SQL Server 2005 T-SQL (SS2K5) Datediff versus Convert for datetime comparison (ignoring time part) RE: Datediff versus Convert for datetime comparison (ignoring time part)

  • Although without testing it I can't quantify it, I think the first would perform better, my rationale is that it should be a fairly simple math operation where only the numbers to the left of the decimal would be evaluated.

    To prove the second item won't even work:

    DECLARE @test-2 datetime

    SET @test-2 = GETDATE()

    SELECT CONVERT( datetime, @test-2, 112 )

    GO

    I think you'd have to convert it to text to do the comparison and text operations are going to be more expensive..

    If I may offer an alternative, can you add a calculated column that filters off the time and is set to persisted, then you could do a direct comparison and the cost of the stripping of the date would occur a single time for each record at the moment of insertion.

    CEWII