c# datediff code example
Example 1: c# calculate difference between two dates in days
(EndDate - StartDate).TotalDays
(EndDate.Date - StartDate.Date).Days
Example 2: c# datediff minutes
using System;
using System.Linq;
public class Demo {
public static void Main() {
DateTime date1 = new DateTime(2018, 7, 15, 08, 15, 20);
DateTime date2 = new DateTime(2018, 8, 17, 11, 14, 25);
TimeSpan ts = date2 - date1;
Console.WriteLine("No. of Minutes (Difference) = {0}", ts.TotalMinutes);
}
}
Output
No. of Minutes (Difference) = 47699.0833333333