sqlsql-serversql-server-2005oraclet-sql

Trunc(sysdate) in SQL Server


What is the equivalent of:

TRUNC(SYSDATE) 

...in SQL Server 2005?


Solution

  • Recommended:

    DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))
    

    This is another alternative, but it's risky because of casting to a FLOAT. It's also been demonstrated to not scale performance as well as the DATEADD/DATEDIFF approach.

    CAST(FLOOR(CAST(GETDATE() AS FLOAT)) AS DATETIME)