15,039,149 members
5.00/5 (1 vote)
See more:
hi ..

how i get start and end date of week..

i will pass .. Week number and year ...
or Any Date

and it return start and end date of that week...

example

week number = 1

year = 2012

1/1/2012 8/1/2012

week number 48

year = 2011

1/2/2012 6/1/2012

I TRY THIS CODE

C#
```DateTime strtdt = DateTime.ParseExact(tx_dt.Text, "dd/MM/yyyy", null);

GregorianCalendar cal = new GregorianCalendar(GregorianCalendarTypes.Localized);
int week = cal.GetWeekOfYear(strtdt, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);

int year = strtdt.Year;

DayOfWeek day = DayOfWeek.Monday;
DateTime startOfYear = new DateTime(year, 1, 1);

// The +7 and %7 stuff is to avoid negative numbers etc.
int daysToFirstCorrectDay = (((int)day - (int)startOfYear.DayOfWeek) + 7) % 7;

DateTime FirstDay = startOfYear.AddDays(7 * (week - 1) + daysToFirstCorrectDay);

TextBox4.Text = FirstDay.ToString("dd/MM/yyyy");
```

but it working fine only for year .. .when previoues year week is 53...
its working fine for 2011 , 2012 .. but when i m checking for 2013 it giving next week date
Posted
anushripatil 10-Jan-12 5:55am

http://stackoverflow.com/questions/1497586/how-can-i-calculate-find-the-week-number-of-a-given-date

Solution 3

thnks for all ... i just going to wrong side ...

i can simply achive that

by this,,,
C#
```DateTime Firstday = dt.AddDays(-(int)dt.DayOfWeek);
```

v6

Solution 2

Hi,

The year 2013 starts from Tuesday. So when you take the first week by taking first Monday, your code returns the second week.
As per you code logic, I understood you calculated first Monday as first week.
So it returns the the second week of dates.
v3

Solution 4

Hi,

Here you can get a method to get first day of the given week & year.
Just change the logic as your need