12,511,665 members (47,232 online)
Rate this:
See more:
Hi !

I am able to get Week No. of the Current Date (Code):
```DateTime dt1 = Convert.ToDateTime(DateTime.Now.ToString("MM/dd/yyyy"));
int yyyy = dt1.Year; int MM = dt1.Month; int dd = dt1.Day;
Int32 weekNo = ci.Calendar.GetWeekOfYear(new DateTime(yyyy, MM, dd), ci.DateTimeFormat.CalendarWeekRule, ci.DateTimeFormat.FirstDayOfWeek );```

Now I want to get 1st Date from a Given Week No of the given Year.
Posted 14-Dec-12 21:26pm
arya.anu 15-Dec-12 6:03am

The code correctly puts the start of week 1, 2009 at 29-12-2008. The CalendarWeekRule probably should be a parameter.

Note that the weekNum should be >= 1

Rate this:

## Solution 1

```static DateTime FirstDateOfWeek(int year, int weekNum, CalendarWeekRule rule)
{
Debug.Assert(weekNum >= 1);

DateTime jan1 = new DateTime(year, 1, 1);

int daysOffset = DayOfWeek.Monday - jan1.DayOfWeek;
Debug.Assert(firstMonday.DayOfWeek == DayOfWeek.Monday);

var cal = CultureInfo.CurrentCulture.Calendar;
int firstWeek = cal.GetWeekOfYear(firstMonday, rule, DayOfWeek.Monday);

if (firstWeek <= 1)
{
weekNum -= 1;
}

DateTime result = firstMonday.AddDays(weekNum * 7);```
v2
Rate this:

## Solution 2

Hi, I wrote it by hand but hope it'll help :)
```public static DateTime GetYearWeekFirstDay(int year, int week)
{
var days = 7 * (week - 1) + 1;

if (days > 366)
throw new InvalidDataException("Invalid week numbers!");

var date = new DateTime(year, 1, 1);

if (date.DayOfWeek != DayOfWeek.Sunday)

var count = 1;

while (count != days)
{
count++;
}

return date;
}
```
v3

Top Experts
Last 24hrsThis month
 OriginalGriff 225 David_Wimbley 205 CPallini 105 ppolymorphe 93 Midi_Mick 90
 OriginalGriff 8,184 Maciej Los 4,139 ppolymorphe 4,124 David_Wimbley 3,536 Karthik Bangalore 3,196