views:

760

answers:

1

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?

+4  A: 

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 ...
Ed Harper
Fantastic, thanks a lot!
Marc