如何在SQL之前30天获得。
答案 0 :(得分:101)
<强> T-SQL 强>
declare @thirtydaysago datetime
declare @now datetime
set @now = getdate()
set @thirtydaysago = dateadd(day,-30,@now)
select @now, @thirtydaysago
或更简单
select dateadd(day, -30, getdate())
<强> MYSQL 强>
SELECT DATE_ADD(NOW(), INTERVAL -30 DAY)
答案 1 :(得分:13)
在MS SQL Server中,它是:
SELECT getdate() - 30;
答案 2 :(得分:2)
SELECT (column name) FROM (table name) WHERE (column name) < DATEADD(Day,-30,GETDATE());
示例。
SELECT `name`, `phone`, `product` FROM `tbmMember` WHERE `dateofServicw` < (Day,-30,GETDATE());
答案 3 :(得分:1)
尝试将其添加到您的where
子句中:
dateadd(day, -30, getdate())