When I use SQL to choose a date, it returns 2011-02-25 21:17:33.933. However, I simply require the Date portion, which is 2011-02-25. I’m not sure how I’m going to accomplish it.
Asked by Neeraj
For SQL Server 2008, follow these steps:
Please refer to https://docs.microsoft.com/en-us/sql/t-sql/functions/getdate-transact-sql
Answered by Prad9
I’m guessing he’s looking for a string.
select convert(varchar(10), '2011-02-25 21:17:33.933', 120)
The value 120 instructs the convert function that the input date should be in the format yyyy-mm-dd hh:mi:ss.
Answered by bernd_k
The quickest is datediff, for example.
select dateadd(d, datediff(d,0, [datecolumn]), 0), other.. from tbl
If you simply require the value, you can skip the dateadd, for example.
select ... WHERE somedate <= datediff(d, 0, getdate())
where datediff(d, 0, getdate()) suffices to return today’s date without the time component.
Answered by RichardTheKiwi
CAST(GETDATE() as date) worked for me, and it was quite simple.
Answered by Anna-leny
CAST( FLOOR( CAST( GETDATE() AS FLOAT ) ) AS DATETIME )
Answered by Brandon Frohbieter
Post is based on https://stackoverflow.com/questions/5125609/how-to-select-date-without-time-in-sql