Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
1.07/5 (5 votes)
See more:
Is it possible to convert age to date of birth using C#.Net

C#
int dob = Convert.ToInt32(txtAge.Text);
//DateTime date=Convert.ToString(dpDOB.Text);
DateTime date = Convert.ToDateTime(dpDOB.Text);
int day = Convert.ToInt32(date.Day);
int month = Convert.ToInt32(date.Month);
int year = Convert.ToInt32(date.Year);
int sub = year - dob;
string day1 = Convert.ToString(date.Day);
string month1 = Convert.ToString(date.Month);
string year1 = Convert.ToString(sub);

string strdate = day1 + "/" + month1 + "/" + year1;
dpDOB.Text = Convert.ToDateTime(strdate).ToString();
Posted
Updated 24-Sep-14 19:46pm
v2
Comments
ZurdoDev 24-Sep-14 8:55am    
Where are you stuck?
King Fisher 24-Sep-14 8:57am    
what you tried So far?

CSS
DateTime date = DateTime.Now;
            int year=date.Year - 32; // 32 is age of the person
          string dateofbith=  year + "/" + date.Month + "/" + date.Day; // here you can change the format of the date
 
Share this answer
 
DateTime today = DateTime.Today;
int age = today.Year - bday.Year;
if (bday > today.AddYears(-age)) age--;

@ http://stackoverflow.com/questions/9/how-do-i-calculate-someones-age-in-c[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900