在现有日期添加月份

时间:2014-11-27 16:10:31

标签: sql-server tsql

如果我有一个现有的日期列,我该如何在该日期添加一定的月份?

示例,类似这样的

UPDATE TrackingData
SET DATEADD(mm, 18, ExpiryDate)    -- ExpiryDate is the date column I want to add the months to
WHERE EmployeeID = @EmployeeID

亲切的问候

3 个答案:

答案 0 :(得分:4)

非常接近......

UPDATE TrackingData
SET ExpiryDate = DATEADD(MONTH, 18, ExpiryDate)
WHERE EmployeeID = @EmployeeID

答案 1 :(得分:3)

只需指定column (ExpiryDate)中必须更新的SET

UPDATE TrackingData
SET    ExpiryDate = Dateadd(MONTH, 18, ExpiryDate)
WHERE  EmployeeID = @EmployeeID 

答案 2 :(得分:2)

UPDATE TrackingData

SET ExpiryDate = DATEADD(mm,18,ExpiryDate)--ExpiryDate represents the date field I want to add the months to

WHERE EmployeeID = @EmployeeID