Home Forums SQL Server 2005 T-SQL (SS2K5) datetime => how to have complete date with 00:00:00.000 RE: datetime => how to have complete date with 00:00:00.000

  • Either of the following is what I consider to be a "best practice". They're both very fast but the first one edges out the second when it comes to millions of rows if you need to apply it to something that large.

    SELECT CAST(DATEDIFF(dd,0,GETDATE()) AS DATETIME),

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

    Replace the GETDATE() with whatever date you may have including dates in a column from a table. Just don't forget to add the FROM clause for the table. 😀

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)