Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieve last full week in MS Query

Status
Not open for further replies.

gj0519

MIS
May 8, 2003
69
US
I have a query where I only want the previous weeks data.
I have it working in Access but I can not get this to work in Excel. Using Office 2k, querying DB2 database.
Any suggestions?

Thanks,

Gj
Code:
 ((Format([SHARE]![CLOSE_DATE],"wwyy"))=Format(DateAdd('ww',-1,Date()),"wwyy")))
 
Try Datediff

WHERE DATEDIFF('dd', CLOSE_DATE, CURRENT_DATE) = 7
 
The code posted in the original question mixes single and double quotes and this is unlikely to work. Access tends to use double quotes. Most ODBC drivers and back end databases are going to want single quotes.

The datediff solution above gives a rolling 7 day selection which is not what the original code does. However, you could probably replace 'dd' with 'ww' and 7 with 1 to get back to fixed weeks.
 



Hi,

I prefer to calculate a date based on the run date. In my company, a report will either be run for the work week (Sat-Fri) or the nominal work week (Mon-Sun). So I use something like this...
Code:
Where MyDate Between INT((Date()-2)/7)*7+2 and INT((Date()-2)/7)*7+2+7
so no matter what day of the week I run the report, I get the SAME week range.

Skip,
[sub]
[glasses] [red][/red]
[tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top