C# 計算差異天數

C# 計算差異天數

  1. string startDate = "2007/07/01";
  2. string endDate = "2007/07/07";
  3. DateTime dtStart = DateTime.ParseExact (startDate, "yyyy/MM/dd", null );
  4. DateTime dtEnd = DateTime.ParseExact (endDate, "yyyy/MM/dd", null );
  5. // 計算差異天數
  6. TimeSpan tsDay = dtEnd - dtStart;
  7. int dayCount = ( int ) tsDay.TotalDays;