hi,
i was working on calculate the birthdate when user select the date,month,year by combobox. the age should display on textbox. i have wrote some code but it show the
error messsage.
can any one solve this please
public static int CalculateAge(DateTime birthDate)
{
DateTime now = DateTime.Today;
int years = now.Year - birthDate.Year;
if
(now.Month < birthDate.Month || (now.Month == birthDate.Month && now.Day < birthDate.Day))
--years;
return years;
}
on button click event the following coding is working
int year = Convert.ToInt32(comboBox1.Text );
int month = Convert.ToInt32(comboBox2.Text); // it contain month in string format
int day = Convert.ToInt32(comboBox3.Text );
[B] DateTime birthDate = new DateTime(year, month, day);[/B] // error
MessageBox.Show("Your Age is:" + Convert.ToString(CalculateAge(birthDate)));
error message = Year, Month, and Day parameters describe an un-representable DateTime.