开发者

how to get the 30 days before date from Todays Date

开发者 https://www.devze.com 2022-12-30 01:57 出处:网络
How do you get the 30 d开发者_运维问答ays before today in SQL.T-SQL declare @thirtydaysago datetime

How do you get the 30 d开发者_运维问答ays before today in SQL.


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)


In MS SQL Server, it is:

SELECT getdate() - 30;


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


Try adding this to your where clause:

dateadd(day, -30, getdate())
0

精彩评论

暂无评论...
验证码 换一张
取 消