dt1 subtract dt2 to get the month count between them - CSharp System

CSharp examples for System:DateTime Calculate

Description

dt1 subtract dt2 to get the month count between them

Demo Code

// Copyright (C) Microsoft Corporation.  All rights reserved.
using System;/* w ww. ja v a  2 s .  c o  m*/

public class Main{
        /// <summary>
        /// dt1 subtract dt2 to get the month count between them
        /// </summary>
        /// <returns>the months between dt1 and dt2</returns>
        internal static int SubtractByMonth(DateTime dt1, DateTime dt2)
        {
            return (dt1.Year - dt2.Year) * 12 + (dt1.Month - dt2.Month);
        }
}

Related Tutorials