SQL Server how to get the 30 days before date from Todays Date

3zwjbxry  于 2023-03-07  发布在  其他
关注(0)|答案(4)|浏览(188)

How do you get the 30 days before today in SQL.

9jyewag0

9jyewag01#

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

( DATEADD on BOL/MSDN )

MYSQL

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

( more DATE_ADD examples on ElectricToolbox.com )

gg0vcinb

gg0vcinb2#

In MS SQL Server, it is:

SELECT getdate() - 30;

mnowg1ta

mnowg1ta3#

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());
jyztefdp

jyztefdp4#

Try adding this to your where clause:

dateadd(day, -30, getdate())

相关问题