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)

  • WHERE date_col1 >= DATEADD(DAY, DATEDIFF(DAY, 0, date_col2), 0)

    AND date_col1 < DATEADD(DAY, DATEDIFF(DAY, 0, date_col2) + 1, 0)

    Or:

    WHERE date_col1 BETWEEN DATEADD(DAY, DATEDIFF(DAY, 0, date_col2), 0) AND DATEADD(MS, -3, DATEADD(DAY, DATEDIFF(DAY, 0, date_col2) + 1, 0))

    Scott Pletcher, SQL Server MVP 2008-2010