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

dyamic list of the last, say, 20 weeks. 1

Status
Not open for further replies.

timtom

Programmer
Jul 12, 2001
78
GB
Hi, has anyone got any code which will return a list of weeks previous to this week, giving something looking a bit like this :

11/02/2002 - 17/02/2002
04/02/2002 - 10/02/2002
28/02/2002 - 03/02/2002
21/02/2002 - 27/02/2002

etc.

Help would be much appreciated for this, the most annoying page I ever did.

Thanks
Sarah
User_timtom.jpg
WASN'T FIT ENOUGH FOR THE POLICE FORCE
 
dateAdd() is the function you're looking for.

Say I have a date already in a variable called thisMonday, and I want to fill an array of 20 elements with previous mondays. Here's how I might accomplish that:

dim i, weekArray(20)
for i = 0 to 19
weekArray(i) = dateAdd("D",-7*i,thisMonday)
next

This is assuming that 'thisMonday' contains a valid start date that you wish to begin subtracting from, where the 0 element of the array would hold the same value as 'thisMonday' when the loop is complete.

:)
paul
penny1.gif
penny1.gif
 
Thanks very much Paul, you've really helped me out. Using datediff I can find out the particular week that the outputs of this loop fall into, and now people can choose the week they want.

However, boss says just displaying one date (and not the monday/sunday either) will confuse users. Is there any way I can find out the start and end dates of the particular week that a day (the weekarray(i) variable) falls into? I have thought about this until my head hurts.

Thanks
User_timtom.jpg
WASN'T FIT ENOUGH FOR THE POLICE FORCE
 
Why dont you just work out the monday and subtract one to get the sunday
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top