protected void btn_Click(object sender, EventArgs e)
{
string dt=combobox1.selectedvalue+"/"+combobox2.selectedvalue+"/"+
combobox3.selectedvalue;
System.DateTime dateOfBirth=Convert.ToDateTime(dt);
TimeSpan ts=new TimeSpan();
System.DateTime currentDate=DateTime.Now();
ts=currentDate.Subtract(dateOfBirth);
int years=0;
int months=0;
int days=0;
years=(ts.Days/366);
DateTime workingDate = dateOfBirth.AddYears(years);
ts= currentDate - workingDate;
months = timeSpan.Days / 31;
workingDate = workingDate.AddMonths(months);
days = currentDate.Subtract(dateOfBirth.AddYears(years).AddMonths(months)).Days;
TextBox1.Text=concatenate the values of years,months and days which you get from above.
}
Also, you need to take into considerations some special conditions such as the date of birth is 31/12/2012 and the currentdate is 01/01/2013...some conditions need to be checked...have a look at that...I dont remember those now.
The above code will accept values from all the 3 combo boxes in a string variable and then a TimeSpan object will calculate the diff between current date and the date of birth.
Also the highest entity which TimeSpan() shows is the number of days..Hence we need to multiply the TimeSpan diff with enitity "Days" and divide it by 366 to get the number of years..
Hope the above helps...
Converted In VB
Protected Sub btn_Click(sender As Object, e As EventArgs)
Dim dt As String = (combobox1.selectedvalue + combobox2.selectedvalue & "/") + combobox3.selectedvalue
Dim dateOfBirth As System.DateTime = Convert.ToDateTime(dt)
Dim ts As New TimeSpan()
Dim currentDate As System.DateTime = DateTime.Now()
ts = currentDate.Subtract(dateOfBirth)
Dim years As Integer = 0
Dim months As Integer = 0
Dim days As Integer = 0
years = (ts.Days / 366)
Dim workingDate As DateTime = dateOfBirth.AddYears(years)
ts = currentDate - workingDate
months = timeSpan.Days / 31
workingDate = workingDate.AddMonths(months)
days = currentDate.Subtract(dateOfBirth.AddYears(years).AddMonths(months)).Days
End Sub
regards
-anurag