Friday, May 1, 2015

asp.net Get Date Difference In Months

    public static Int32 GetDateDiffInMonths(string CurrentDate, string targetDate)
        {
            DateTime startDate = System.Convert.ToDateTime(CurrentDate);
            DateTime endDate = System.Convert.ToDateTime(targetDate);
           
            int monthsApart = 12 * (startDate.Year - endDate.Year) + startDate.Month - endDate.Month;
            return Math.Abs(monthsApart);
        }

No comments:

Post a Comment