return only the date from datatime

  • select convert(char(10),getdate(),101)

  • SELECT dateadd(dd, datediff(dd,0, getdate()),0)

    The varchar method works, but is slower. See - http://sqlinthewild.co.za/index.php/2008/09/04/comparing-date-truncations/

    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
  • Thank you

    Is working.I've tryied CTE with split for the date and it wasn't working properly...

    Nice solution:)

  • If you are trying to get a count by Date, you can use

    SELECT CONVERT(CHAR(10), Your_Date, 121) as GroupingDate, COUNT(*)

    FROM Your_Table

    GROUP BY CONVERT(CHAR(10), Your_Date, 121)

    ORDER BY GroupingDate

    If you are trying to get a count by Date and Hour, you can use

    SELECT CONVERT(CHAR(13), Your_Date, 121) as GroupingDateHour, COUNT(*)

    FROM Your_Table

    GROUP BY CONVERT(CHAR(13), Your_Date, 121)

    ORDER BY GroupingDateHour

  • select datepart(dd,getdate()) will give the only the date as 26

    select Convert(varchar(10),getdate(),101) will returns the date as '09/26/2008'

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

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