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

Compare dates so that second date must be greater than or equal to 18

1 Answer 160 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Dorababu
Top achievements
Rank 1
Dorababu asked on 19 Jun 2012, 01:21 PM
Hi all I am having two RadDatePicker on my form, I would like to compare these 2 dates so that the second date must be less than or equal to 18, means employee age should be greater than or equal to 18.

I would like to achieve this with out using javascript is it possible

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 20 Jun 2012, 12:19 PM
Hi Dorababu,

I suppose you want to calculate the year difference between two dates. Try the following code snippet.

ASPX:
<telerik:RadDatePicker ID="picker1" runat="server"></telerik:RadDatePicker>
<telerik:RadDatePicker ID="picker2" runat="server"></telerik:RadDatePicker>
<asp:Button ID="btn1" runat="server" onclick="btn1_Click" />

C#:
protected void btn1_Click(object sender, EventArgs e)
    {
        DateTime dt1 = picker1.SelectedDate.Value;
        DateTime dt2 = picker2.SelectedDate.Value;
        int t=dt1.Year - dt2.Year;
        if (t < 18)
        {
            Response.Write("age is less than 18");
        }
        else
            Response.Write("age is greater than 18");
    }

Hope this helps.

Thanks,
Princy.
Tags
Calendar
Asked by
Dorababu
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or