CSharp examples for System:DateTime Calculate
Compares the value of this instance to a specified System.DateTime value and returns an integer that indicates whether this instance is earlier than, the same as, or later than the specified System.DateTime value.
using System;// w ww . ja v a2 s . co m public class Main{ /// <summary> /// Compares the value of this instance to a specified System.DateTime value /// and returns an integer that indicates whether this instance is earlier than, /// the same as, or later than the specified System.DateTime value. /// </summary> /// <param name="source">The date.</param> /// <param name="dateToCompare">The date to compare.</param> /// <returns></returns> public static int CompareTo(this DateTime source, DateTime? dateToCompare) { DateTime safeToCompare = DateTime.MinValue; if (dateToCompare != null || dateToCompare.HasValue) safeToCompare = dateToCompare.Value; return source.CompareTo(safeToCompare); } }