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?


For SQL Server 2008:

Convert(date, getdate())  

Please refer to https://docs.microsoft.com/en-us/sql/t-sql/functions/getdate-transact-sql


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.


The fastest is datediff, e.g.

select dateadd(d, datediff(d,0, [datecolumn]), 0), other..
from tbl

But if you only need to use the value, then you can skip the dateadd, e.g.

select ...
WHERE somedate <= datediff(d, 0, getdate())

where the expression datediff(d, 0, getdate()) is sufficient to return today's date without time portion.


Use CAST(GETDATE() as date) that worked for me, simple.


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

AS DATETIME
)

http://www.bennadel.com/blog/122-Getting-Only-the-Date-Part-of-a-Date-Time-Stamp-in-SQL-Server.htm