I m new in asp.net
I want when user select date of birth then automatically calculate their age and fill up the age text box and I performing one logic but somewhere My logic is wrong?
code:
default.aspx
<form>
<label for="date"><b>Date Of Birth:</b></label>
<asp:Calendar ID="txtdate" placeholder="Select Your Date Of Birth" runat="server" OnSelectionChanged="txtdate_SelectionChanged"></asp:Calendar>
<label for="age"><b>Age:</b></label>
<asp:TextBox ID="txtage" runat="server" placeholder="Age"></asp:TextBox>
</form>
default.aspx.cs
protected void txtdate_SelectionChanged(object sender, EventArgs e)
{
DateTime birthdate=txtdate.SelectedDate.Date; //select date from calender
int age = DateTime.Now.Year - birthdate.Year;
txtage.Text = age.ToString();
}
protected void age_TextChanged(object sender, EventArgs e)
{
}
when I select the date of birth from calender(1/12/2017) In the watch window then display the 3 year but I want to display 2 years 4 months 24 days
watch window:
which place I need to change my logic?