mha.dk

Random thoughts of wisdom - the personal blog of Michael Holm Andersen

Calculate you age

I needed to calculate a persons age the other day, and came up with this simple code:

DateTime myBirthDay = new DateTime(1970, 9, 5);
TimeSpan diffAge = DateTime.Now.Date - myBirthDay.Date;
int myAge = new DateTime(diffAge.Ticks).Year - 1;

Comments are closed