Reputation: 9282
In SQL Server 2008 I need to update just the date part of a datetime field.
In my stored procedure I receive the new date in datetime format. From this parameter I have to extract the date (not interested in time) and update the existing values date part.
How can I do this?
Upvotes: 8
Views: 9665
Reputation: 21495
One way would be to add the difference in days between the dates to the old date
UPDATE TABLE
SET <datetime> = dateadd(dd,datediff(dd,<datetime>,@newDate),<datetime>)
WHERE ...
Upvotes: 14