Link to home
Start Free TrialLog in
Avatar of websss
websssFlag for Kenya

asked on

sql date +14 days

i need to filter data on the last 14 days

the code would be something like
Select 06-07, 07-08, 08-09 from UsageLogs where BranchId = 54 AND reportDate between now + 14 days

Open in new window


what code would be correct for this
the data type is date2
Avatar of Steve Wales
Steve Wales
Flag of United States of America image

You want the dateadd function:

http://technet.microsoft.com/en-us/library/ms186819.aspx

Where reportdate between getdate() and dateadd(dd, getdate(), -14)

Open in new window


Should do the trick - between "now" and "14 days ago"
ASKER CERTIFIED SOLUTION
Avatar of lcohan
lcohan
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Basically you wan all the records from the table that have a ReportDate in the last 14 days from right now, which means the ReportDate is greater than right now minus 14 days:
Select 
	06-07, 07-08, 08-09 
from 
	UsageLogs 
where 
	BranchId = 54 
	AND reportDate > DATEADD(dd,-14, getdate())

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial