days of week
-
hi guys i want to get first and last date of week given by a week number and year is there any way ? regards.
Tauseef A Khan MCP Dotnet framework 2.0.
Have a look at this: http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^] You can use various datetime properties available to get what you want.
-
hi guys i want to get first and last date of week given by a week number and year is there any way ? regards.
Tauseef A Khan MCP Dotnet framework 2.0.
Following is the code for retrieving first and last day of the given date. You need to give date instead of just year and week no. In following code I have also counted sunday as one of the week day. You can omit sunday in switch case. DateTime dt; dt = DateTime.Today; DateTime date = DateTime.Now; System.Globalization.CultureInfo cult_info = System.Globalization.CultureInfo.CreateSpecificCulture("no"); System.Globalization.Calendar cal = cult_info.Calendar; int weekNo = cal.GetWeekOfYear(dt, cult_info.DateTimeFormat.CalendarWeekRule, cult_info.DateTimeFormat.FirstDayOfWeek); MessageBox.Show(weekNo.ToString()); int plus1 = 0; int minus1 = 0; switch (date.DayOfWeek) { case DayOfWeek.Monday: plus1 = 6; minus1 = 0; break; case DayOfWeek.Tuesday: plus1 = 5; minus1 = 1; break; case DayOfWeek.Wednesday: plus1 = 4; minus1 = 2; break; case DayOfWeek.Thursday: plus1 = 3; minus1 = 3; break; case DayOfWeek.Friday: plus1 = 2; minus1 = 4; break; case DayOfWeek.Saturday: plus1 = 1; minus1 = 5; break; case DayOfWeek.Sunday: plus1 = 0; minus1 = 6; break; } MessageBox.Show(date.AddDays(-minus1).ToShortDateString()); MessageBox.Show(date.AddDays(plus1).ToShortDateString());
Jinal Desai
-
Following is the code for retrieving first and last day of the given date. You need to give date instead of just year and week no. In following code I have also counted sunday as one of the week day. You can omit sunday in switch case. DateTime dt; dt = DateTime.Today; DateTime date = DateTime.Now; System.Globalization.CultureInfo cult_info = System.Globalization.CultureInfo.CreateSpecificCulture("no"); System.Globalization.Calendar cal = cult_info.Calendar; int weekNo = cal.GetWeekOfYear(dt, cult_info.DateTimeFormat.CalendarWeekRule, cult_info.DateTimeFormat.FirstDayOfWeek); MessageBox.Show(weekNo.ToString()); int plus1 = 0; int minus1 = 0; switch (date.DayOfWeek) { case DayOfWeek.Monday: plus1 = 6; minus1 = 0; break; case DayOfWeek.Tuesday: plus1 = 5; minus1 = 1; break; case DayOfWeek.Wednesday: plus1 = 4; minus1 = 2; break; case DayOfWeek.Thursday: plus1 = 3; minus1 = 3; break; case DayOfWeek.Friday: plus1 = 2; minus1 = 4; break; case DayOfWeek.Saturday: plus1 = 1; minus1 = 5; break; case DayOfWeek.Sunday: plus1 = 0; minus1 = 6; break; } MessageBox.Show(date.AddDays(-minus1).ToShortDateString()); MessageBox.Show(date.AddDays(plus1).ToShortDateString());
Jinal Desai
-
-
ya we can do in that way also. I am just interested in solution. (However it is not optimized solution)
Jinal Desai
-
-
Jinal Desai - LIVE wrote:
However it is not optimized solution
Quite the reverse! ;)
It's time for a new signature.