Compare the year,month,day of dt1 and dt2 - CSharp System

CSharp examples for System:DateTime Calculate

Description

Compare the year,month,day of dt1 and dt2

Demo Code

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

public class Main{
        /// <summary>
        /// Compare the year,month,day of dt1 and dt2
        /// </summary>
        /// <returns>
        /// less than 0    : dt1 &lt; dt2; 
        /// equal 0        : dt1 == dt2; 
        /// greater than 0 : dt1 &gt; dt2
        /// </returns>
        internal static int CompareYearMonthDay(DateTime dt1, DateTime dt2)
        {
            DateTime first = new DateTime(dt1.Year, dt1.Month, dt1.Day);
            DateTime second = new DateTime(dt2.Year, dt2.Month, dt2.Day);
            TimeSpan ts = first - second;
            return ts.Days;
        }
}

Related Tutorials