This is a migrated thread and some comments may be shown as answers.

Calculate month difference using radMonthYearPicker

1 Answer 135 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Stardome20
Top achievements
Rank 1
Stardome20 asked on 10 Dec 2012, 01:42 PM

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

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 11 Dec 2012, 04:24 AM
Hi,

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

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

C#:
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.

Regards,
Princy.
Tags
General Discussions
Asked by
Stardome20
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or