RadCalendar WeekNumber

5 posts, 0 answers
  1. Rob Venable
    Rob Venable avatar
    48 posts
    Member since:
    Dec 2009

    Posted 21 Apr 2010 Link to this post

    Is it possible to return the WeekNumber of a RadCalendar on PostBack?
    I need to pass the weeknumber (and probably the year also) to my function so that I can return sales for this week.

    Is this possible?

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 22 Apr 2010 Link to this post

    Hi Rob,

    Here is the code snippet to retrieve the WeekNumber of selected date of Calendar.

        protected void Button1_Click(object sender, EventArgs e) 
            DateTime dt = (DateTime)RadCalendar1.SelectedDate;     
            int number = GetWeekNumber(dt);  // Week number 
            int year = dt.Year;   // Year 
        public int GetWeekNumber(DateTime dtDate) 
            CultureInfo ciCurr = CultureInfo.CurrentCulture; 
            int weekNum = ciCurr.Calendar.GetWeekOfYear(dtDate, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday); 
            return weekNum+1; 

  3. Rob Venable
    Rob Venable avatar
    48 posts
    Member since:
    Dec 2009

    Posted 22 Apr 2010 Link to this post

    Thanks Princy. That's exactly what I needed.
  4. @CC
    @CC avatar
    6 posts
    Member since:
    Jun 2008

    Posted 08 Nov 2010 Link to this post


    RadDatePicker with WeekNo showing:
    <telerik:RadDatePicker ID="uxDatePicker" runat="server" AutoPostBack="true" OnSelectedDateChanged=OnSelectedDateChanged Skin="Windows7" Culture="English (United States)" >
       <Calendar ID="Calendar1" runat="server" ShowColumnHeaders="true" ShowRowHeaders="true" >
          <ClientEvents OnLoad="AddEvent" />

    Based on the above code by princy, the week no does not match with the radDatePicker's week number for say '12/28/2010' the function returns 53 whereas radDatePicker says 1. Any suggestions?

  5. Vasil
    Vasil avatar
    1642 posts

    Posted 10 Nov 2010 Link to this post


    Actually 12/28/2010 is in 52 week, in both US and ISO standards. So both 51 and 1 are wrong.

    Try the following code-snippets:

    <telerik:RadDatePicker ID="RadDatePicker1" AutoPostBack="true" runat="server" OnSelectedDateChanged="RadDatePicker1_SelectedDateChanged">
        <Calendar runat="server">
        <DateInput runat="server" DisplayDateFormat="M/d/yyyy" DateFormat="M/d/yyyy" AutoPostBack="True">
        <DatePopupButton ImageUrl="" HoverImageUrl=""></DatePopupButton>
    <label id="Label1" runat="server">

    protected void Page_Load(object sender, EventArgs e)
        CultureInfo c = new CultureInfo("en-US");
        c.DateTimeFormat.CalendarWeekRule = CalendarWeekRule.FirstFourDayWeek;
        c.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Monday;
        RadDatePicker1.Calendar.CultureInfo = c;
    protected void RadDatePicker1_SelectedDateChanged(object sender, Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs e)
        DateTime dt = (DateTime)RadDatePicker1.SelectedDate;
        CultureInfo c = RadDatePicker1.Calendar.CultureInfo;
        int number = c.Calendar.GetWeekOfYear(dt, c.DateTimeFormat.CalendarWeekRule, c.DateTimeFormat.FirstDayOfWeek);
        Label1.InnerText = number.ToString();

    This should get you the right day when you use GetWeekOfYear.

    Be aware that you still will have divergence in some cases.
    For example:
        12/31/2012 is 53 week by the ISO standard.
        01/01/2013 is 1 week by the ISO standard.
    Both this days, however are in the same week. In calendar week column, you can see only one number. It can not show 53 and 1 at the same time. And it shows 1.

    All the best,
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top