T-SQL: How to update just date part of datetime field?

后端 未结 1 1974
终归单人心
终归单人心 2021-01-02 10:10

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 h

相关标签:
1条回答
  • 2021-01-02 11:01

    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 ...
    
    0 讨论(0)
提交回复
热议问题