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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto selecting dates for weekly figures.

Status
Not open for further replies.

tilltek

Programmer
Mar 8, 2001
298
PH
I have a bit of code that adds figures from sales sheets for given periods.
These periods (week 1, week 2 week 3 etc) are....
Week 1: from the 1st of the month to the first Sunday.
Week 2: from the following Saturday to the following Sunday

and so on, NOTE that the first and last weeks may well be only a few days.

September week 1 would be


*----- 1st week of month to the first Sunday (only 4 days)
store {^2004/09/01} to MDATEA
store {^2004/09/04} to MDATEB
store "01/09/2004 to 04/09/2004" to MDATEC
do enterit

*----- 2nd of month Monday to Sunday
store {^2004/09/05} to MDATEA
store {^2004/09/11} to MDATEB
store "01/09/2004 to 04/09/2004" to MDATEC
do enterit

and so on
MDATEA is the first day, MDATEB is the last day and MDATEC gives me a title

I have to manually change these each month.

Here at last is my question.

How could I set this up to be automatic on, say, the selection of a month and year?
I would like to be able to select a month and year from a menu or similar and have the code work out the weeks.

Thanks in advance.

Ken
 
I'm a little confused...you say "to the first Sunday" but then your date ends on a saturday (2006/09/04) ...after that you say from "Monday to Sunday" but your dates are Sunday to Saturday (2004/09/05 to 2004/09/11). This confusions the issue quite a bit. That having been said...use the DOW() function on the first of any month of a given year and you'll know how many days until that Saturday. If you are going from Sunday to Saturday as a full week then it's a snap...7 - DOW() gives you the number of days you'll need to advance to get that first week...then it's just a matter of adding 7 to the previous MDATEA and MDATEB to get the next set of date bounds.

boyd.gif

 
I'm going to go with the dates you showed and not what you said (either way you should be able to work from this example I wrote), so assuming the weeks are from Sunday to Saturday here is a function that will return an array with the dates for MDATEA and MDATEB (just cut-n-paste the code below into a prg and run it from within VFP to see how it works):
Code:
DIMENSION aryBounds(1, 2)
ReturnArrayWeeks(2004, 9, @aryBounds)

**************************************
*****Displaying Array for Example*****
*****      Purposes Only         *****
**************************************
LOCAL lnCounter
FOR lnCounter = 1 TO ALEN(aryBounds,1)
	?"FROM " + DTOC(aryBounds(lnCounter,1)) + " TO " + DTOC(aryBounds(lnCounter,2))
	?
ENDFOR
***********************************

***********************************
PROCEDURE ReturnArrayWeeks(tnYear, tnMonth, taBounds)
***********************************
	DIMENSION taBounds(1,2) && Make sure it is right starting dimensions
	LOCAL ldUpper, ldLower, lnCounter
	ldLower = DATE(tnYear, tnMonth, 1)
	ldUpper = ldLower + 7 - DOW(ldLower)
	lnCounter = 1
	DO WHILE MONTH(ldUpper) = tnMonth
		taBounds(lnCounter,1) = ldLower
		taBounds(lnCounter,2) = ldUpper
		ldLower = ldUpper + 1
		ldUpper = ldUpper + 7
		lnCounter = lnCounter + 1
		DIMENSION taBounds(lnCounter, 2)
	ENDDO
	taBounds(lnCounter,1) = ldLower
	taBounds(lnCounter,2) = ldUpper - DAY(ldUpper) && last day of month
ENDPROC

boyd.gif

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top