年齢計算

自分が今何歳だったかわからなくなることはよくあるよね。

static void Main( string[] args ) {
	Console.WriteLine( GetAge( DateTime.ParseExact( "1900/01/01", "yyyy/MM/dd", null ) ) );
}

private static int GetAge(DateTime from) {
	var to = DateTime.Now;
	var year = to.Year - from.Year;
	if ( to.Month < from.Month || ( to.Month == from.Month && to.Day < from.Day ) ) {
		year--;
	}
	return year;
}