Last post Sep 18, 2017 02:37 PM by jonnygareth30
Sep 15, 2017 04:13 PM|jonnygareth30|LINK
I Have used the below code to display the week number by use of the calendar function. when I run this on my local machine the week number is correct after selecting a date on my calendar. When trying on my hosted website the week number is 1 week ahead.
My hosted server is a Windows Server 2008 R2 Standard. Would there be a setting on the server that could be affecting the week numbers within my software?
protected void WeekEndDate_SelectionChanged(object sender, EventArgs e)
WeekEnd_DateTextBox.Text = WeekEndDateCalendar.SelectedDate.ToShortDateString();
WeekEndDateCalendar.Visible = false;
DateTime date = WeekStartDateCalendar.SelectedDate;
DateTime newdate = WeekEndDateCalendar.SelectedDate;
CultureInfo myCI = new CultureInfo("en-GB");
System.Globalization.Calendar myCal = myCI.Calendar;
CalendarWeekRule myCWR = myCI.DateTimeFormat.CalendarWeekRule;
DayOfWeek myFirstDOW = myCI.DateTimeFormat.FirstDayOfWeek;
WeekNoLabel.Text = myCal.GetWeekOfYear(date, myCWR, myFirstDOW).ToString();
Any assistance is greatly appreciated.
Sep 15, 2017 04:59 PM|PatriceSc|LINK
See https://msdn.microsoft.com/en-us/library/bz9tc508.aspx and force the culture to en-GB if your app always use that. More likely the server uses for example en-US which uses another
convention for computing week numbers.
Sep 18, 2017 02:31 AM|Jean Sun|LINK
In addition to
PatriceSc's suggestions, please try change your hosting server's timezone settings to the same as your local machine.
Here is the link which shows how to configure the timezone settings in Windows 2008, please take it as reference.
Sep 18, 2017 02:37 PM|jonnygareth30|LINK
Thank you both for your answers, the issue has now been resolved. Thank you very much.