Search code examples
sqlsql-serversql-server-2005

How to select date without time in SQL


When I select date in SQL it is returned as 2011-02-25 21:17:33.933. But I need only the Date part, that is 2011-02-25. How can I do this?


Solution

  • I guess he wants a string.

    select convert(varchar(10), '2011-02-25 21:17:33.933', 120)
    

    120 here tells the convert function that we pass the input date in the following format: yyyy-mm-dd hh:mi:ss.