如何在今天日期之前30天获得

时间:2010-05-14 09:58:10

标签: sql sql-server datetime

如何在SQL之前30天获得。

4 个答案:

答案 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())

DATEADD on BOL/MSDN

<强> MYSQL

SELECT DATE_ADD(NOW(), INTERVAL -30 DAY)

more DATE_ADD examples on ElectricToolbox.com

答案 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())