nassss

Untitled

Jan 12th, 2020
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. static int CalculateBusinessDays(DateTime firstDate, DateTime secondDate)
  2. {
  3. TimeSpan interval = (secondDate - firstDate);
  4. int totalWorkingDays = 0;
  5.  
  6. int numberOfWeeks = interval.Days / 7;
  7. int numberOfWorkingDays = numberOfWeeks * 5;
  8.  
  9. int daysLeft = interval.Days % 7;
  10. for (int i = 0; i < daysLeft; i++)
  11. {
  12. DayOfWeek test = (DayOfWeek)(((int)firstDate.DayOfWeek + i) % 7);
  13. if (test>= DayOfWeek.Monday && test <= DayOfWeek.Friday)
  14. {
  15. totalWorkingDays++;
  16. }
  17. }
  18. return totalWorkingDays + numberOfWorkingDays;
Advertisement
Add Comment
Please, Sign In to add comment