using c#, how can i get my age base on the current date? my birthdate is 4/11/1972? the result should be 35? kindly help me pls?
Printable View
using c#, how can i get my age base on the current date? my birthdate is 4/11/1972? the result should be 35? kindly help me pls?
You want to paste out whatever code you have so someone could fix it?
int age;
DateTime bday;
DateTime cdate;
bday = DateTimePicker1.Value;
cdate = DateTimePicker2.Today;
age = cdate - bday;
Try something likeCode:int years = DateTime.Now.Year - BirthDate.Year;
if (DateTime.Now.Month < BirthDate.Month ||
(DateTime.Now.Month == BirthDate.Month &&
DateTime.Now.Day < BirthDate.Day))
years--;