Number of days in date range, excluding weekends and other dates, in C#

前端 未结 7 1053
别那么骄傲
别那么骄傲 2020-12-15 01:16

I have a C# method like this:

public static int DaysLeft(DateTime startDate, DateTime endDate, Boolean excludeWeekends, String excludeDates)
{
}
7条回答
  •  无人及你
    2020-12-15 01:43

    Here's pseudocode for a different approach which I've used in SQL:

    Find the total number of days between the two dates
    Subtract number of weekends
    Remove a day if the start date is a sunday
    Remove a day if the start date is a saturday
    Remove any other days you don't want (see my comment above for how to do this in c#)

提交回复
热议问题