Calculate month difference using radMonthYearPicker

2 posts, 0 answers
  1. Stardome20
    Stardome20 avatar
    7 posts
    Member since:
    Nov 2012

    Posted 10 Dec 2012 Link to this post

    I have 2 radMonthYearPicker(1 is for start Date another 1 is for end Date) I want to calculate the month different between this 2 date.

    for my start Date, I set my month as oct and year 2012. for my end Date, I set my month as dec and year 2013

    Base on this 2 RadMonthYearPicker, the month apart should be 14 month

    The only code I can find out is RadMonthYearPicker.selectedDate

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

    Posted 10 Dec 2012 Link to this post


    Following is the sample code that I tried to achieve your scenario.

    <telerik:RadMonthYearPicker ID="RadMonthYearPicker1" runat="server">
    <telerik:RadMonthYearPicker ID="RadMonthYearPicker2" runat="server">
    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />

    protected void Button1_Click(object sender, EventArgs e)
        if (RadMonthYearPicker1.SelectedDate > RadMonthYearPicker2.SelectedDate)
            int monthdifference=   ((RadMonthYearPicker1.SelectedDate.Value.Year - RadMonthYearPicker2.SelectedDate.Value.Year) * 12) + RadMonthYearPicker1.SelectedDate.Value.Month - RadMonthYearPicker2.SelectedDate.Value.Month;

    Hope this helps.

Back to Top