Re: Week # function?
Posted in 1994
>From: edmond@pipeline.com (Edmond Ying) >Subject: Week # function? >Date: 18 Feb 1994 23:14:33 -0500 >X-Informix-List-Id: <news.5597> > >Any one know if there is a 4gl function that return the week # >in a year? There isn't one as such. It isn't difficult to write, however, provided you know how you want your weeks to be aligned with the start of the year. The basic calculation is: year_no = YEAR(given_date) day_in_year = given_date - MDY(1, 1, year_no) + 1 week_no = (day_in_year + week_offset(year_no)) / 7 The first line gives you the day in the year for a given date, with 1 Jan being day 1 in the year. The function week_offset returns a number which, when added to day_in_year, gives you the answer you wanted. There are a variety of factors to consider: * Do you ever get week 0? * Do you ever get week 53? * If you don't get either, how do you manage it? * Is Sunday the first day of the week or is Monday? It is because of these variables that a single standard solution is not provided -- it would be wrong for some (probably even most) people all of the time. Yours, Jonathan Leffler (johnl@informix.com) #include <disclaimer.h>