Getting Only date | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Getting Only date

Hi All,
Can I get only date without time. example:- 2007-03-21 14:33:22.670 I must get only 2007-03-21
thank you with regards
aruna
select dateadd(day, datediff(day, 0, getdate()), 0)
KH
select dateadd(day, datediff(day, 0, getdate()), 0)
the result for above statement is 2007-03-21 00:00:00.000 the result should not give time values like 2007-03-21 00:00:00.000
Thank you
There is no way to return a value of a DATETIME data type without a time portion. If you don’t want that midnight time, you need to convert it to another data type such as VARCHAR or INT. However, as soon as you convert back to DATETIME, you have this time portion. —
Frank Kalis
Moderator
Microsoft SQL Server MVP
Webmaster:http://www.insidesql.de
You can display the date as yyyy-mm-dd without the time by using CONVERT(VARCHAR(10), GETDATE(), 120) … but as soon as you store this in a DATETIME column, the midnight time will be displayed again. I thought they already added a new data type for date-without-time to SQL 2005?
Nope, they dropped it somewhen between the CTPs and the RTM. You would have to resort to a CLR UDT in this case. 🙁 —
Frank Kalis
Moderator
Microsoft SQL Server MVP
Webmaster:http://www.insidesql.de
That was actually one of the reasons why I was looking forward to SQL 2005 – how inconsiderate of them.
]]>