How do you get the 30 days before today in SQL.
To get the date that is 30 days prior to the current date with JavaScript, we can call the setDate method with the current date subtracted by 30 to get the date 30 days before the current date.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With