This post illustrate you a very common question in C# that how to calculate date difference between two given dates.
The given method takes date1 and date2 as input parameter and return the difference of dates in days as an integer format.
/// <summary>
/// Returns number of days diff between 2 given dates.
/// </summary>
public static int DateDiff(DateTime StartDate, DateTime EndDate)
{
int NumDaysDiff;
TimeSpan ts = EndDate.Subtract(StartDate);
NumDaysDiff = ts.Days;
return NumDaysDiff;
}
you can contact me in case of any issues.
0 comments:
Post a Comment