compareto c# datetime code example
Example 1: how to compare datetime in c#
DateTime.Compare(datetime1, datetime2);
Example 2: c# how does comparing datetime work
using System;
public class Demo {
public static void Main(){
DateTime d1 = new DateTime(2019, 12, 20, 6, 20, 40);
DateTime d2 = new DateTime(2019, 11, 20, 6, 20, 40);
Console.WriteLine("DateTime 1 = {0:dd} {0:y}, {0:hh}:{0:mm}:{0:ss} ", d1);
Console.WriteLine("DateTime 2 = {0:dd} {0:y}, {0:hh}:{0:mm}:{0:ss} ", d2);
int res = DateTime.Compare(d1, d2);
Console.WriteLine(res);
}
}