Albert,

RE:
SET VAR vWeek = (((MOD(JDATE(.vDate),1000)) + 7 - IDWK(.vDate))/7)
-----------------------

        (JDATE(.vDate)) converts any date entered into a Julian date.
This date is formatted with the year first and followed by the number
of the day in that year.
(JDATE('06/12/1995')) = 1995163

        (MOD(1995163,1000)) calculates the remainder after
1995163 is divided by 1000.  The modulus, or remainder of 163
represents the 163rd day of 1955.

        Dividing 163 by 7 would calculate week number 23.29
i.e. the 24th week. The limitation to this calculation is that it
calculates the week based upon the number of full weeks
from the first day of the year.  So if the first day of the year
is on Thursday, each week will begin on Thursday unless a
provision is made to change the day on which the week is to begin.

        Fortunately this may be adjusted using the IDWK command
which returns the day of the week where Monday is 1.

        (IDWK('06/12/1995'))  returns the day of 1, or Monday.

        Allowing that the week began on Monday, Monday is day 1,
Tuesday-2, Wednesday-3, Thursday-4, Friday-5, Saturday-6, Sunday-7.
In order to adjust the beginning day of the year to begin on Sunday,
we have to add six days to the day automatically calculated which
is Monday:  (1, i.e.Monday + 6 = 7, i.e.  Sunday).  This is calculated
by adding the number representing the day of the week on which
you wish to start the week (1-Monday, 2-Tuesday, ... 7-Sunday)
and subtracting from that number the day of the week calculated
for the date you enter (IDWK(.vDate)).

        (+ 7 - (IDWK(.vDate)))

        Dividing by 7 calculates the number of the week
based on the adjusted day on which the week begins.

       ( (163 + (7 - 1)) / 7 ) = 24.14  or the 25th week.

Adjusting the formula for the week to begin on Saturday:

SET VAR vWeek = (((MOD(JDATE(.vDate),1000)) + 6 - IDWK(.vDate))/7)

Although I would probably parse it as follows:

SET VAR vWeek = ( ( (MOD( (JDATE(.vDate)) ,1000)) + ( 7 - (IDWK(.vDate)) ) ) /7)

        Randy Peterson



Albert Berry wrote:

> For anyone who doesn't have the new IWK function available, this will give you the 
>calendar week, ending on Sunday, for any date. First reply figuring out the logic AND 
>describing it in clear English AND altering it to return calendar weeks ending on 
>Saturday will up my conference ante by $10, attributed to her/him.
>
> SET VAR vDate DATE
> SET VAR vWeek INTEGER
> SET VAR vDate = <any date>
> SET VAR vWeek = (((MOD(JDATE(.vDate),1000)) + 7 - IDWK(.vDate))/7)

Reply via email to