Microsoft KB Archive/100431

INF: User-Defined Function for Computing the Week of the Year

PSS ID Number: Q100431 Article last modified on 08-31-1993

2.00 2.50 2.50a | 2.50 2.50a MS-DOS | WINDOWS

Summary: To compute the week of the year (1 through 52), use the following user-defined function (UDF): SET TALK OFF mdate = { / / } @5,15 SAY “Enter a date:” GET mdate READ weeknum = getWeek(mdate) wait window str(weeknum) ********************************************************************* * This UDF builds a date based on the format 01/01/year entered. * It subtracts that day minus 1 from the passed date, and divides * by 7.02 (the number of days in a week). It then adjusts the answer * to a fixed number, and returns the answer.   Parameters: startDate - Date in question.   Variables: firstDay - The first day of the startDate year. * lastDay - The last day of the previous year. * wNum - The number of days from 01/01/year entered * to the date entered. ********************************************************************* FUNCTION getWeek PARAMETERS startDate firstDay = “01/01/” + str(year(startDate),4,0) LastDay = ctod(firstDay)-1 wNum = (startDate - LastDay) / 7.02 wNum = ROUND(wNum,0) RETURN(wNum)

Additional reference words: 2.00 2.50 2.50a Copyright Microsoft Corporation 1993.