본문 바로가기
다물칸 주소복사
조회 수 1631 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
Extra Form
구분 팁&트릭
출처 내가작성
  1.         public static int ProcGetAge(string BirthDay, bool KoreanAgeType = true) // BirthDay Format - YYYY-MM-DD
  2.         {
  3.             int Age = 0;
  4.  
  5.             int BirthYear = Convert.ToInt32( BirthDay.Substring(2, 2));
  6.  
  7.             int NowYear =DateTime.Now.Year;
  8.  
  9.             if (BirthDay.Substring(0, 2) == "19")
  10.             {
  11.                 Age = (NowYear - (1900 + BirthYear));
  12.             }
  13.             else
  14.             {
  15.                 Age = (NowYear - (2000 + BirthYear));
  16.             }
  17.  
  18.             if (KoreanAgeType)
  19.             {
  20.                 int BirthMonth = Convert.ToInt32(BirthDay.Substring(5, 2));
  21.                 int nowMonth = DateTime.Now.Month;
  22.  
  23.                 if (BirthMonth == nowMonth)
  24.                 {
  25.                     int BirthDays = Convert.ToInt32(BirthDay.Substring(8, 2));
  26.                     int nowDay = DateTime.Now.Day;
  27.  
  28.                     if (BirthDays <= nowDay)
  29.                         Age = Age + 1;
  30.                 }
  31.                 else if (BirthMonth < nowMonth)
  32.                     Age = Age + 1;
  33.             }
  34.             return Age;
  35.         }