Search


Tuesday, December 16, 2008

Calculating a Duration in InfoPath

   1: //Calculating a Duration 
   2: //In some scenarios, it might be a requirement to calculate 
   3: //the total number of days in a given period. 
   4: //For example, in an expense report solution, 
   5: //you might need to identify the duration of the reporting period based 
   6: //on a start date and end date. In the GetDuration function, 
   7: //two date string values are passed as arguments to retrieve a duration string value. 
   8: private string GetDuration(string startDate, string endDate) 
   9: { 
  10:     string retValue = string.Empty; 
  11:     if (startDate != string.Empty && endDate != string.Empty) 
  12:     { 
  13:         long longStartDate = DateTime.Parse(startDate).ToFileTimeUtc(); 
  14:         long longEndDate = DateTime.Parse(endDate).ToFileTimeUtc(); 
  15:         long longDayCount = (longEndDate - longStartDate) / 864000000000 + 1; 
  16:         retValue = longDayCount.ToString(); 
  17:     } 
  18:     return retValue; 
  19: }

No comments:

Post a Comment