.NET Date Compare: Count the amount of working days since a date?

前端 未结 7 1127
别那么骄傲
别那么骄傲 2020-12-03 08:16

What\'s the easiest way to compute the amount of working days since a date? VB.NET preferred, but C# is okay.

And by \"working days\", I mean all days excluding Satu

7条回答
  •  离开以前
    2020-12-03 09:07

    The easiest way is probably something like

    DateTime start = new DateTime(2008, 10, 3);
    DateTime end = new DateTime(2008, 12, 31);
    int workingDays = 0;
    while( start < end ) {
      if( start.DayOfWeek != DayOfWeek.Saturday
       && start.DayOfWeek != DayOfWeek.Sunday ) {
          workingDays++;
      }
      start = start.AddDays(1);
    }
    

    It may not be the most efficient but it does allow for the easy checking of a list of holidays.

提交回复
热议问题