Also, is there any way of inputting the week number and get the first date of that week?
Regards
Allan Michaelsen
I'm using the Silverlight 2009 Q1 package
4 Answers, 1 is accepted
There is no easy way to reuse the WeekNumber value outside of the RadCalendar, but here is how the calendar calculates the week number, hopefully you will be able to reuse it where necessary:
//RadCalendar is an instance of the calendar: |
//Get the specific calendar culture or use the current one: |
CultureInfo cultureToUse = myCalendar.Culture ?? CultureInfo.CurrentCulture; |
//Get the custom CalendarWeekRule or use the culture-specific: |
CalendarWeekRule calendarWeekRuleToUse = myCalendar.CalendarWeekRule ?? cultureToUse.DateTimeFormat.CalendarWeekRule; |
//Do the same for the FirstDayOfWeek: |
DayOfWeek firstDayOfWeekToUse = myCalendar.FirstDayOfWeek ?? cultureToUse.DateTimeFormat.FirstDayOfWeek; |
var selectedDate = myCalendar.SelectedDate.Value; |
//Get the week number in a culture-specific safe way: |
var weekNum = cultureToUse.Calendar.GetWeekOfYear(selectedDate, calendarWeekRuleToUse, firstDayOfWeekToUse); |
Also here is how you can get the date of a first day of a week:
//Get the first date of a week is culture specific way uses some enum calculations: |
var firstDateOfWeek = selectedDate; |
if (firstDayOfWeekToUse < selectedDate.DayOfWeek) |
{ |
firstDateOfWeek = selectedDate.AddDays((int)firstDayOfWeekToUse - (int)selectedDate.DayOfWeek); |
} |
else if (firstDayOfWeekToUse > selectedDate.DayOfWeek) |
{ |
firstDateOfWeek = selectedDate.AddDays(-(7-(int)firstDayOfWeekToUse + (int)selectedDate.DayOfWeek)); |
} |
It may be a good idea to include these as helper methods for the Calendar, we will consider that.
All the best,
Miroslav
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
I was using this code below to get the weeknumber but it's not working. Can you help?
protected
void RadDatePicker1_SelectedDateChanged(object sender, Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs e)
{
CultureInfo cultureToUse = RadDatePicker1.Calendar.CultureInfo;
CalendarWeekRule calendarWeekRuleToUse = RadDatePicker1.Calendar.DateTimeFormat.CalendarWeekRule;
DayOfWeek firstDayOfWeekToUse = RadDatePicker1.Calendar.DateTimeFormat.FirstDayOfWeek;
string weekNum = cultureToUse.Calendar.GetWeekOfYear(RadDatePicker1.Calendar.SelectedDate, calendarWeekRuleToUse, firstDayOfWeekToUse).ToString();
Label18.Text = weekNum.ToString();
}
This is a forum about RadDatePicker for Silverlight. It seems your question is related to the ASP.NET Ajax control. Could you please re-post your question in the appropriate forum to avoid misleading the other community members of this forum.
Thank you
Sincerely yours,
Veselin Vasilev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
This is quick follow-up.
Your approach seems to be correct and conforms to the guidelines provided in this forum post. We will appreciate if you start a new thread under the RadCalendar for ASP.NET AJAX forum and provide details about what fails during the code execution or what the incorrect result you get is. Thus we will do our best to advice you further.
Best regards,
Sebastian
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.