Re: calendar week algorithm
Posted in 2000
The algorithm should be fairly straight forward: 1) Compute the day of the week for 1/1/YYYY (This can be done using "Zeller's Congruence"), adjusted so that Sunday returns 0, Monday=1, etc. 2) Compute the Julian Day for the date in question. 3) Add the result of 1 to the result of 2, and subtract 1. 4) Divide by 7 saving the integer portion. That is the week number, with 0 being the first week. 5) Add 1 to the result to convert to weeks 1-53. Zeller's congruence, BTW, is as follows: D is the day of the month. M is the month with March being 1 and January and February being months 11 and 12 of the previous year. C is the century. Y is the year. d is the day of the week with Sunday as 0 and Saturday as 6. d = ((26*M - 2)//10 + D + Y + Y//4 + C//4 - 2*C) mod 7 (// is integer division with truncation) HTH, Doug "Raymond Michalek" <rfm@tpso.com> wrote in message news:3967121A.EBB6C568@tpso.com... > Hi, > > Does anybody have or know an algorithm to calculate from a given date > the calendar week or week number? > In Oracle is a standard function available! > Is there a function in Informix? > If there isn't, can someone give me an algorithm to calculate the week > number? > or > does someone have a spl to calculate the week number? > > > Thanks > > Raymond Michalek > >