본문 바로가기

FLEX

[FLEX] 두 날짜 사이의 개월 수 구하기

      private function getMonths(startDate:Date, endDate:Date):Number
      {
         if (startDate > endDate)  {
             var tmp:Date = endDate;
             endDate = startDate;
             startDate = tmp;
         }

          var numMonths:Number = 0;
    
          // Get number of months in years
          numMonths += (endDate.fullYear - startDate.fullYear) * 12
          numMonths += endDate.month - startDate.month;
          //numMonths += (endDate.day - startDate.day) / 30; // This needs fixing
    
          return numMonths;
     }

출처 : http://www.mail-archive.com/flexcoders@yahoogroups.com/msg31546.html