Reputation: 15138
How to get the date of a specific week in a specific year?
For example: I have the data week 30, year 2009 - how I can get the date of the week?
Language is C#
Upvotes: 1
Views: 250
Reputation: 23770
A sample for code that does it:
int workWeek = 30;
int year = 2009;
var firstDayOfYear = new DateTime(year, 1, 1);
var firstDayOfWorkWeek = firstDayOfYear.AddDays((workWeek - 1) * 7);
This code assumes that the work week start on the day of the 1/1/YYYY (meaning week can start from Wednesday for example).
If you want to normalize it to Sunday:
firstDayOfWorkWeek =
firstDayOfWorkWeek.AddDays(-(int) firstDayOfWorkWeek.DayOfWeek);
Upvotes: 2