[thelist] date ranges

Matt Warden mwarden at gmail.com
Thu Jul 7 12:02:40 CDT 2005


On 7/7/05, Mike D. Johnson <mdjohnson at bcbe.org> wrote:
> I don't understand what you've recommended but I certainly appreciate
> your willingness to help.  Let me try to explain my problem better...
> Here is what I have:
> ds is an array that has the start and end dates of a reservation:
> reservationStartDate  |  reservationEndDate
>         7/1/2005            |   7/3/2005
>         7/6/2005            |   7/6/2005
> What I need is to create a second array (named allDays) that looks like
> this:
> 7/1/2005
> 7/2/2005
> 7/3/2005
> 7/6/2005
> It needs to include all reservationStartDates, all reservationEndDates
> and all of the days in between those where applicable

My point was that I don't understand why you would want to do this. It
is a waste of space, because the ranges already provide exactly this
information. It seems like you are doing it in an attempt to make some
other part of your programming simpler, but I think this is
ill-advised. Anyway, if you want something like this, here's some
pseudo code:

foreach reservation in ds
   dBeginRange = reservation[0]
   dEndRange = reservation[1]
   dRanger = dBeginRange
   while dRanger <= dEndRange
      allDays[i] = dRanger
      add 1 day to dRanger
      add 1 to i
   end while
end foreach

The difficult part will be dealing with i, which is why that part is
not included. This is especially difficult because you are dealing
with VBScript, where you will have to determine the size of the
allDays array based on the size of the ranges when you create the
array (or else keep ReDim'ing it, which is a performance hog).

You might want to take another look at my original reply. If you need
help figuring out what it's doing, I can try to put it in more
VBScript-like pseudo code.

Matt Warden
Miami University
Oxford, OH, USA

This email proudly and graciously contributes to entropy.

More information about the thelist mailing list