how to get the 30 days before date from Todays Date. in Sql using Query
+3
A:
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())
MYSQL
SELECT DATE_ADD(NOW(), INTERVAL -30 DAY)
amelvin
2010-05-14 10:00:12
Just realised, this is written in T-Sql (Sql Server), if the answer is needed for MySql then something like: SELECT DATE_ADD(NOW(), INTERVAL -30 DAY) is the equivalent.
amelvin
2010-05-14 10:05:57
Just add this to your answer:)
hgulyan
2010-05-14 10:09:51
@hgulyan - will do!
amelvin
2010-05-14 10:43:25
A:
In DB2, you can use:
select current date - 30 days as some_time_ago from sysibm.sysdummy1;
You can actually do all sorts of wondrous datetime additions and subtractions such as:
current date + 2 years + 3 months + 10 days
current time + 4 hours - 6 minutes + 10 seconds
days(current date) - days(date('2010-01-01'))
paxdiablo
2010-05-14 10:17:51
+1
A:
SELECT TRUNC (SYSDATE - 30) FROM DUAL;
Executed today using ORACLE PL/SQL, it will produce:
April 14th, 2010 00:00:00
The chicken in the kitchen
2010-05-14 10:20:23