Method 1:
Datetime.compare (T1,T2) compares two date size, row front small, row in the back big , for example: 2011-2-1 is less than 2012-3-2
The return value is less than 0: T1 is less than T2.
The return value equals zero: T1 equals T2.
The return value is greater than 0: T1 is greater than T2.
Using System; Using System.Collections.Generic; Using System.Linq; Using System.Text; Namespace ConsoleApplication1 { class program { static void Main (string[] args) { DateTime T1 = DateTime.Parse ("2011-2-2"); DateTime t2 = datetime.parse ("2011-3-1"); if (Datetime.compare (t1, T2) > 0) Console.WriteLine ("T1 > t2"); if (Datetime.compare (t1, t2) = = 0) Console.WriteLine ("T1 = = t2"); if (Datetime.compare (t1, T2) < 0) Console.WriteLine ("T1 < T2");}}
Method 2.
Using system;using system.collections;public class myclass{public static void Main () {DateTime dt1 = DateTime.Parse ("2006 -04-01 ");D atetime DT2 = DateTime.Parse (" 2006-05-01 "); TimeSpan ts = dt2. Subtract (DT1); Console.WriteLine (TS. Totaldays); Console.ReadLine ();}}
System.TimeSpan diff1 = Date2. Subtract (date1);
This method can be used to specify the difference in value
Subtract two datetime directly, the result is a timespan, so that you can take the timespan of days and other properties
C # Compare size of two dates two case resolution