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

2 posts, 0 answers
  1. Dorababu
    Dorababu avatar
    95 posts
    Member since:
    May 2012

    Posted 19 Jun 2012 Link to this post

    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
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 20 Jun 2012 Link to this post

    Hi Dorababu,

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

    <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" />

    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");
                Response.Write("age is greater than 18");

    Hope this helps.

  3. DevCraft R3 2016 release webinar banner
Back to Top