Innova
Innova

Reputation: 4981

How to get the 30 days before date from today's date

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

Upvotes: 98

Views: 322881

Answers (4)

Try adding this to your where clause:

dateadd(day, -30, getdate())

Upvotes: 3

Ashley2605
Ashley2605

Reputation: 41

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

Upvotes: 4

Merin Nakarmi
Merin Nakarmi

Reputation: 3418

In MS SQL Server, it is:

SELECT getdate() - 30;

Upvotes: 19

amelvin
amelvin

Reputation: 9061

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)

Upvotes: 159

Related Questions