コード例 #1
0
        public int Age()
        {
            int      year  = Convert.ToInt32(DateOfBirth.Substring(4, 4));
            int      month = Convert.ToInt32(DateOfBirth.Substring(2, 2));
            int      date  = Convert.ToInt32(DateOfBirth.Substring(0, 2));
            DateTime bDay  = new DateTime(year, month, date);
            DateTime now   = DateTime.Today;
            int      age   = now.Year - bDay.Year;

            if (bDay > now.AddYears(-age))
            {
                age--;
            }
            return(age);
        }