Hello everybody ,
I am developing a app in .net in which I have to show the age of a person.
It will work with this format.
- user enters the date-of-birth

- the age is automatically calculated till today.

Age format must be xx-years, xx -months, xx-days
I have already developed the algorithm for it but when I try to enter the age which is less than 1 year the I see some bugs which are poping up.
Here are the codes in C#



Code:
try

{

DateTime todays_date, date_of_birth;

todays_date = DateTime.Today;

//Date of Birth is accepted via user input at the date_time_picker

date_of_birth = dtpTaxCalcForOthers_DOB.Value;

TimeSpan date_difference;

date_difference = todays_date.Subtract(date_of_birth);



//AGE_ALGORITHM

int total_days = date_difference.Days;

int calculated_ageYY, calculated_ageMM, calculated_ageDD, remaining_days;

if ((total_days % 365) == 0)

{

calculated_ageYY = total_days / 365;

calculated_ageMM = 0;

calculated_ageDD = 0;

}

else

{

calculated_ageYY = total_days / 365;

remaining_days = total_days % 365;

if ((remaining_days % 30) == 0)

{

calculated_ageMM = remaining_days / 30;

calculated_ageDD = 0;

}

else

{

calculated_ageMM = remaining_days / 30;

calculated_ageDD = remaining_days % 30;

}

}

//Displaying the result to the text-box

txtTaxCalcForOthers_AgeYY.Text = calculated_ageYY.ToString();

txtTaxCalcForOthers_AgeMM.Text = calculated_ageMM.ToString();

txtTaxCalcForOthers_AgeDD.Text = calculated_ageDD.ToString();

}

catch

{

}