// 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; using System.Globalization; namespace E { public class Program { 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; } public static void Main(string[] args) { DateTime dt = new DateTime(2007, 12, 31); Console.WriteLine(dt.ToString("dddd dd/MM/yyyy")); GregorianCalendar gc = new GregorianCalendar( GregorianCalendarTypes.Localized ); Console.WriteLine(gc.GetWeekOfYear( dt, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday ).ToString() ); Console.WriteLine(WeekNumber(dt.Year, dt.Month, dt.Day)); } } }