SQL 如何从今天的日期获取日期前 30 天
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2833241/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 06:13:36 来源:igfitidea点击:
how to get the 30 days before date from Todays Date
提问by Innova
How do you get the 30 days before today in SQL.
你如何在 SQL 中获得今天之前的 30 天。
回答by amelvin
T-SQL
查询语句
declare @thirtydaysago datetime
declare @now datetime
set @now = getdate()
set @thirtydaysago = dateadd(day,-30,@now)
select @now, @thirtydaysago
or more simply
或者更简单
select dateadd(day, -30, getdate())
MYSQL
MYSQL
SELECT DATE_ADD(NOW(), INTERVAL -30 DAY)
回答by Merin Nakarmi
In MS SQL Server, it is:
在 MS SQL Server 中,它是:
SELECT getdate() - 30;
SELECT getdate() - 30;
回答by Ashley2605
SELECT (column name) FROM (table name) WHERE (column name) < DATEADD(Day,-30,GETDATE());
Example.
例子。
SELECT `name`, `phone`, `product` FROM `tbmMember` WHERE `dateofServicw` < (Day,-30,GETDATE());
回答by Chester Porcioncula Velasco
Try adding this to your where
clause:
尝试将其添加到您的where
子句中:
dateadd(day, -30, getdate())