Claus on Code

A data dudes random musings about code, bugs, products, life etc.

What week is it?

I noticed many people are using the weeks, as a way of describing time. I have never used weeks, so I never know where to look up what date, a week is.

I have always thought that it would be easy to make a program in .NET that do the work for me, and it really was.

You can see the result below.

If you want to know what week a specific date is, click the calendar, and the week will be shown in textbox below.

If you want to know what date a specific week starts with, select a date in the calendar, in the year you want to get the week from. Type in the week in the textbox, and click the what date button.

***Example removed***

Oh, and if you want to use the code, it is just these few lines:

int GetWeekOfYear(DateTime date)
GregorianCalendar cal = new GregorianCalendar();
return cal.GetWeekOfYear(date, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);

private DateTime GetDateByWeek(int year, int week)
  DateTime date = new DateTime(year, 1, 1);
return date.AddDays(7 * week – (int)date.DayOfWeek-6);

Leave a Reply

Your email address will not be published. Required fields are marked *