Re: week of year function
Posted in 1998
Steffen Kuebler wrote: > > Hi there, > > I'm searching for a date function which returns me the week of the year. > > Can somebody help me ! Just divide the Julian date by 7 and add one for the partial week if the remainder is non-zero and you count the week containing January 1 as part of this year or last year. If you want to take physical weeks (ie 7 days starting January 1) into consideration or consider whether the first week was a partial week, you can pick any year as a DOW base for the DOW of Jan 1 and then it is easy. Adjusting for leap years, the DOW for any given date shifts forward one day from the previous year (2 in a leap year) so if Jan. 1, 1980 was a Tuesday (it was) then January 1, 1999 will be 1999-1980=19+5(leap days[1980, 1984, 1988, 1992, 1996])=24 days later 24%7=3 so January 1, 1999 will be a Friday (it is). BTW February 5, 1999 is 35 days later and 35%7=0 so that's a Friday also. Anyway, once you know the starting DOW for January 1 and you decide whether that week belongs to the current or previous year and whether midweek days belong to the prior or next week the WeekOfYear calculation is trivial. Hope that this helps. Art S. Kagel