private void button1_Click(object sender, EventArgs e)
{
DateTime dob = new DateTime();
textBox1.Text = dob.ToString();
int age;
age = Convert.ToInt32(textbox2.Text);
age = DateTime.Now.Year - dob.Year;
if (DateTime.Now.DayOfYear < dob.DayOfYear)
age = age - 1;
}
How to claculate the age from dob.This is my form1.cs.any ideas please
Take the difference between the current day and their birth day: days = current day - birth day . Replace these differences in the age formula: age = (years × 365) + (months × 31) + days . This is the person's age in days. Divide the result by 365 to get the age in years.
Ans: To find out a person's age, all you need is that person's year of birth. After this, all you need to do now is subtract the birth year from the ongoing current year and you will have the age. This will help you to calculate the age from the date of birth. Age= 2020- 1966 = 54.
int age = (int) ((DateTime. Now - bday). TotalDays/365.242199);
DateTime today = DateTime.Today;
int age = today.Year - bday.Year;
if (bday > today.AddYears(-age))
age--;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With