Determines whether two object instances represent the same date (have same year/month/day values). - CSharp System

CSharp examples for System:DateTime Year

Description

Determines whether two object instances represent the same date (have same year/month/day values).

Demo Code


using System.Globalization;
using System;/*from w  ww.  j  a  v  a 2s  . com*/

public class Main{
        /// <summary>
    ///   <para>Determines whether two <see cref="DateTime"/> object instances represent the same date (have same year/month/day values).</para>
    /// </summary>
    /// <param name="self">Curent date to compare with the second.</param>
    /// <param name="other">Second date to compare with the current.</param>
    /// <returns><c>true</c> if both <paramref name="self"/> and <paramref name="other"/> have equals date component.</returns>
    /// <seealso cref="IsSameTime(DateTime, DateTime)"/>
    public static bool IsSameDate(this DateTime self, DateTime other)
    {
      return self.Day == other.Day && self.Month == other.Month && self.Year == other.Year;
    }
}

Related Tutorials