Note: For example, between 1900-01-01 and 1900-01-01, one day
private static int DateDiff (DateTime datestart, datetime dateend) { datetime start = Convert.todatetime ( Datestart.toshortdatestring ()); DateTime end = Convert.todatetime (datestart.toshortdatestring ()); TimeSpan SP = end. Subtract (start); Return sp. Days; }
Related Properties for TimeSpan:
Related properties and functions add: Adds to another timespan value. Days: Returns the TimeSpan value that is calculated in day. Duration: Gets the absolute value of the timespan. Hours: Returns the TimeSpan value computed in hours milliseconds: Returns the TimeSpan value computed in milliseconds. Minutes: Returns the TimeSpan value computed in minutes. Negate: Returns the inverse number of the current instance. Seconds: Returns the TimeSpan value computed in seconds. Subtract: Subtracts another TimeSpan value from it. Ticks: Returns the number of ticks for the timespan value. Totaldays: Returns the number of days that the TimeSpan value represents. TotalHours: Returns the number of hours that the timespan value represents. TotalMilliseconds: Returns the number of milliseconds represented by a timespan value. Totalminutes: Returns the number of minutes represented by a timespan value. TotalSeconds: Returns the number of seconds represented by a timespan value.
C # Calculates the number of days difference between two dates