첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
------------------------------------------------------------------------------------------------------------------------------------------------------
728x90
728x170

TestProject.zip
0.00MB

▶ Program.cs

using System;

namespace TestProject
{
    /// <summary>
    /// 프로그램
    /// </summary>
    class Program
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Private

        #region 개월 수 구하기 - GetMonthCount(fromDate, toDate)

        /// <summary>
        /// 개월 수 구하기
        /// </summary>
        /// <param name="fromDate">FROM 날짜</param>
        /// <param name="toDate">TO 날짜</param>
        /// <returns>개월 수</returns>
        private static int GetMonthCount(DateTime fromDate, DateTime toDate)
        {
            int monthCount = 0;

            fromDate = fromDate.Date.AddDays(-(fromDate.Day-1));
            toDate   = toDate.Date.AddDays(-(toDate.Day-1));

            while(toDate.Date > fromDate.Date)
            {
                monthCount++;

                fromDate = fromDate.AddMonths(1);
            }

            return monthCount;
        }

        #endregion
        #region 프로그램 시작하기 - Main()

        /// <summary>
        /// 프로그램 시작하기
        /// </summary>
        private static void Main()
        {
            DateTime fromDate = new DateTime(2017, 3, 3);
            DateTime toDate   = new DateTime(2018, 6, 6);

            int monthCount = GetMonthCount(fromDate, toDate);
 
            Console.WriteLine($"FROM 날짜 : {fromDate  }");
            Console.WriteLine($"TO 날짜   : {toDate    }");
            Console.WriteLine($"개월 수   : {monthCount}");
        }

        #endregion
    }
}
728x90
그리드형(광고전용)
Posted by icodebroker
,