Today's Date Minus 7 days

B

Ben

I have a query that pulls all the records in descending order by a field name
called End Date. I want to pull the records that have occured in the past 7
days only. Here is my SQL code for now: What am I missing?

SELECT tblBuildsWAR.BuildNumber, tblBuildsWAR.PreviousStatus,
tblBuildsWAR.CurrentStatus, tblWAR.StartDate, tblWAR.EndDate
FROM tblWAR INNER JOIN tblBuildsWAR ON tblWAR.WARPK = tblBuildsWAR.WarFK
ORDER BY tblWAR.StartDate DESC;

Please help
 
J

John Spencer

You are missing a WHERE clause to limit the records returned

SELECT tblBuildsWAR.BuildNumber, tblBuildsWAR.PreviousStatus,
tblBuildsWAR.CurrentStatus, tblWAR.StartDate, tblWAR.EndDate
FROM tblWAR INNER JOIN tblBuildsWAR ON tblWAR.WARPK = tblBuildsWAR.WarFK

WHERE [End Date] > DateDiff("d",-7,Date()) and [End Date] <
DateDiff("d",0,Date())

ORDER BY tblWAR.StartDate DESC;

You may need to adjust the DateDiff amounts depending on your definition
of the past seven days.

What I posted should give you records for the prior 7 days not including
today.

'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top