I am designing a practice visual c# program that has you pick your birth date from a dateTimePicker and comparing it to the current date to display in a textBox what your current age is.
I would like to factor in which day of the month you picked to refine the age result rather than just assuming you're a certain age because you were born in that particular month.
This is what I have so far:
public void button1_Click(object sender, EventArgs e)
{
var birthdayYear = dateTimePicker1.Value.Year;
var birthdayMonth = dateTimePicker1.Value.Month;
var birthdayDay = dateTimePicker1.Value.Day;
var currentYear = DateTime.Now.Year;
var currentMonth = DateTime.Now.Month;
var currentDay = DateTime.Now.Day;
int currentAge = DateTime.Now.Year - dateTimePicker1.Value.Year;
if (birthdayMonth >= currentMonth)
{
currentAge--;
}
string currentResult = Convert.ToString(currentAge);
ageResult.Text = currentResult;
}