且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在sql server中的特定日期添加-30天?

更新时间:2023-12-01 11:54:04

这应该有效。

 选择 DATEADD(DAY,-30,GETDATE())


查看MSSQL DATEADD 功能。



你可以这样使用:

  SELECT  
DATEADD(day,-30,Expiredate) as 30DaysBeforeExpireyDate
FROM
tblSource
;





希望它有所帮助。


你可以这样做:

SELECT DATEADD(day,-30,Expiredate)from LastDate from YourTable

i my case i have a Expiredate column and my intention is to get the date before 30 days of Expiredate. how to do that.

This should work.
select DATEADD(DAY , -30,  GETDATE())


Have a look at MSSQLs DATEADD function.

You can use this like:
SELECT
    DATEADD(day,-30, Expiredate) as 30DaysBeforeExpireyDate
FROM
   tblSource
;



Hope it helps.


You can do using this:
SELECT DATEADD(day,-30,Expiredate) as LastDate from YourTable