Efficient way of stripping time part from Datetime.

  • Hi,

    Can you suggest some efficient way of stripping the time part from Datetime column.

    Eg.

    Input : 2008-01-01 12:12:12:223

    Output: 2008-01-01 00:00:00:000

  • DECLARE @TheDate DATETIME

    SET @TheDate = '2008-01-01 12:12:12:223'

    SELECT dateadd(dd, datediff(dd,0, @TheDate),0)

    See http://sqlinthewild.co.za/index.php/2007/11/05/datetime-manipulation/

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Hi,

    And mm-dd-yyyy to dd-mm-yyyy?

  • Don't understand your question. A datetime has no defined format, it's a date, format is a string property. The format that you see in queries is defined by your regional settings and, if you want to see something else, you can use the CONVERT function to convert the date to a varchar in the format that you want to see it as.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Thanks a lot . i got it :w00t:

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply