// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; namespace E { public class Util { public static int WeekNumber(int year, int mon, int day) { int a = (14 - mon) / 12; int y = year + 4800 - a; int m = mon + 12*a - 3; int JD = day + (153 * m + 2)/5 + 365*y + y/4 - y/100 + y/400 - 32045; int d4 = (((JD + 31741 - JD % 7) % 146097) % 36524) % 1461; int L = d4 / 1460; int d1 = ((d4 - L) % 365) + L; return d1 / 7 + 1; } } class MainClass { public static void Test(int year, int week) { Console.WriteLine(year + "/" + week + ":"); //DateTime dt = new DateTime(year, 1, 1); DateTime dt = new DateTime(year-1, 12, 29); while(Util.WeekNumber(dt.Year, dt.Month, dt.Day) > 1) { dt = dt.AddDays(1); } while(Util.WeekNumber(dt.Year, dt.Month, dt.Day) < week) { dt = dt.AddDays(1); } while(Util.WeekNumber(dt.Year, dt.Month, dt.Day) == week) { Console.WriteLine(dt.ToString("dd-MMM-yyyy")); dt = dt.AddDays(1); } } public static void Main(string[] args) { Test(2000, 1); Test(2001, 1); Test(2002, 1); Test(2003, 1); Test(2004, 1); Test(2005, 1); Test(2006, 1); } } }