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?
Update only the MONTH part of a SQL Server date using the DATEADD() function. Similarly, if you have been asked to change the month of the start_date column to specific month for few records of the table based on some condition, then you can use the dateadd() function to do the same. Use below script to change the only day part of the start_date.
How to Return Date Part Only from a SQL Server Datetime datatype Example 1 In this SQL Server example, first, we are going to declare a DateTime variable, and also use the GETDATE() function. Next, we are going to use the CONVERT, CAST , DATEADD , and DATEPART functions to extract the date part only from a SQL server Datetime Datatype .
In SQL Server 2008, Microsoft introduced a new data-type “date”. This data type will store only the date part (day, month and year).
In SQL Server 2008, Microsoft introduced a new data-type “date”. This data type will store only the date part (day, month and year). You can use the date data-type along with CONVERT or CAST to extract the date part from DateTime and DateTime2. 1.
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 ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With