Reputation: 13636
I'm newer in T-SQL.So maybe my question will seem naive.
I need to retrieve current date with help of TSQL query.
I can implement this by GETDATE()
function but the function
returns me this format 04-03-2012 13:58:02,
I need to get only the date without hour minute and seconds.
Any idea how to do this?
Thank you in advance.
Upvotes: 0
Views: 91
Reputation: 103428
This will remove the time from the datetime
object. Therefore it will be in the format 04-03-2012 00:00:00
DECLARE @d datetime
SET @d = GETDATE()
SET @d = DATEADD(dd, 0, DATEDIFF(dd, 0, @d))
SELECT @d
If you wish to not send any time back at all, then this is not strictly a datetime
object, and you should pass it as a string:
SELECT CONVERT(NVARCHAR(10), GETDATE(), 101)
Personally however, I would always send back the value as a datetime
object, and then format the date at application level. Once a date is converted to a string, its bad practice to try and convert this back to a date, and could cause you problems later down the line.
Upvotes: 4