I code therefore I am.

January 21, 2010 at 2:29pm
2 notes
Comments (View)
home

Tags:
CSharp  

age from birthday

Rather than dividing figures by a fixed number days (which ignores special cases like leap years), I find this method quite reliable.

//Given DateTime birthday
TimeSpan span = DateTime.Now - birthday;
DateTime time = DateTime.MinValue + span;
int age = time.Year - 1; 

blog comments powered by Disqus

Notes

  1. sourcerer posted this