Search


Tuesday, December 16, 2008

Calculating a Duration in Infopath C# code

//Calculating a Duration

//In some scenarios, it might be a requirement to calculate

//the total number of days in a given period.

//For example, in an expense report solution,

//you might need to identify the duration of the reporting period based

//on a start date and end date. In the GetDuration function,

//two date string values are passed as arguments to retrieve a duration string value.

private string GetDuration(string startDate, string endDate)

{

string retValue = string.Empty;

if (startDate != string.Empty && endDate != string.Empty)

{

long longStartDate = DateTime.Parse(startDate).ToFileTimeUtc();

long longEndDate = DateTime.Parse(endDate).ToFileTimeUtc();

long longDayCount = (longEndDate - longStartDate) / 864000000000 + 1;

retValue = longDayCount.ToString();

}

return retValue;

}

No comments:

Post a Comment