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?
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.
If you want to return a date type as just a date use
CONVERT(date, SYSDATETIME())
or
SELECT CONVERT(date,SYSDATETIME())
or
DECLARE @DateOnly Datetime
SET @DateOnly=CONVERT(date,SYSDATETIME())
Use CAST(GETDATE() as date) that worked for me, simple.
you can use like this
SELECT Convert(varchar(10), GETDATE(),120)
It's a bit late, but use the ODBC "curdate" function (angle brackes 'fn' is the ODBC function escape sequence).
SELECT {fn curdate()}
Output: 2013-02-01