Barry: This is what I use to meet the ISO
Bill SUBROUTINE WEEKNO (DateIn, WeekOut) ** ** Notes: ** ** Passed Variables: ** DateIn : Internal date representing week number desired ** WeekOut : ISO 8601-formatted Week Number: ** ** ISO 8601 prescribes a format yyyyWnn, where nn is the ordinal week ** number in the year, and the rule is that week 01 in a year is the ** first week that contains four calendar dates in that year. ** ** A week is defined as a seven-day period running from Monday-Sunday. ** Week 1 of any year is defined as the first week containing four days ** of the year, or equivalently the week containing the first Wednesday ** of the year. For example, if January 1 falls on a Friday, then the ** first two days of January fall in week 53 of the preceding year. ** ** To allow for this possibility, this subroutine starts by computing ** the internal date for the Wednesday of the week containing the input ** date. A simple calculation from this gives the correct year number ** and week number for the tag. ! ** Start program run ! ** Calculate the closest Wednesday to the input date. We're using a ** Sunday thru Saturday work week. DayOfWeek = Mod(DateIn, 7) WEDNESDAY = DateIn - DayOfWeek + 3 * ** Convert Wednesday's date to week number. WeekNo = Int((OCONV(WEDNESDAY, 'DJ') - 1)/ 7) + 1 * ** Assemble the yyyyWnn format. WeekOut = OCONV(WEDNESDAY, 'DY') : "W" : WeekNo "R(%2)" * **----------------------------------------------------------------** ** ** ** E N D O F P R O G R A M ** ** ** **----------------------------------------------------------------** * RETURN END > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Barry Brevik > Sent: Thursday, October 27, 2005 11:42 AM > To: 'u2-users@listserver.u2ug.org' > Subject: RE: [U2] Week of the year (UV) > > If I understand the question properly, I believe this will do it: > > PRINT INT(OCONV(DATE(),'DJ')/7) + > OCONV((OCONV(DATE(),'DJ')/7:'')['.',2,1],"S;'1';'0'") > > ...but be aware that even though we think of a year as having > 52 weeks, and a week is 7 days, 7 * 52 = 364. As far as I > know, a year always has 365 days unless it is a leap year > with 366 days. > > Therefore, the above algorithm will return 53 for the last > day of the year, or for the last 2 days if it is a leap year. > > Also, above algorithm might be totally useless if you are > talking about your company's FISCAL year, whatever it is > defined to be. > > Barry Brevik > ------- > u2-users mailing list > u2-users@listserver.u2ug.org > To unsubscribe please visit http://listserver.u2ug.org/ ------- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/