/// <Summary>
/// Calculate the interval between two dates
/// </Summary>
/// <Param name = "DateTime1"> first date and time </param>
/// <Param name = "DateTime2"> Second Date and time </param>
/// <Remarks> Add: cuiwk 2010-05-31 </remarks>
/// <Returns> time interval </returns>
Public string DateDiff (DateTime DateTime1, DateTime DateTime2)
{
String dateDiff = null;
TimeSpan ts1 = new TimeSpan (DateTime1.Ticks );
TimeSpan ts2 = new TimeSpan (DateTime2.Ticks );
TimeSpan ts = ts1.Subtract (ts2). Duration ();
DateDiff = ts. Days. ToString () + "day" +
Ts. Hours. ToString () + "Hour" +
Ts. Minutes. ToString () + "Minute" +
Ts. Seconds. ToString () + "Seconds ";
Return dateDiff;
}
}
Note:
1. The DateTime Value Type represents a specific date time between 00:00:00 on January 1, January 1, 0001 AD and on January 1, December 31, 9999 AD. Therefore, you can use the DateTime value type to describe any time within the expected range. A DateTime value represents a specific time.
2. the TimeSpan value contains many attributes and methods for accessing or processing a TimeSpan value.
The following list covers some of them:
Add: adds the value to another TimeSpan value.
Days: returns the TimeSpan value calculated by the number of Days.
Duration: gets the absolute value of TimeSpan.
Hours: returns the hourly TimeSpan value.
Milliseconds: returns the TimeSpan value in Milliseconds.
Minutes: returns the TimeSpan value calculated in Minutes.
Negate: returns the opposite number of the current instance.
Seconds: returns the TimeSpan value calculated in Seconds.
Subtract: Subtract another TimeSpan value from it.
Ticks: the number of tick values returned for TimeSpan.
TotalDays: returns the number of days indicated by the TimeSpan value.
TotalHours: returns the number of hours represented by the TimeSpan value.
TotalMilliseconds: the number of milliseconds in which the TimeSpan value is returned.
TotalMinutes: returns the number of minutes represented by the TimeSpan value.
TotalSeconds: returns the number of seconds represented by the TimeSpan value.