Skip to content

Instantly share code, notes, and snippets.

@andylshort
Created July 11, 2019 19:58
Show Gist options
  • Save andylshort/395302b3e868f6eb808cd1b8611dc000 to your computer and use it in GitHub Desktop.
Save andylshort/395302b3e868f6eb808cd1b8611dc000 to your computer and use it in GitHub Desktop.
Get work days between two dates
private double GetWorkDays(DateTime Start, DateTime End)
{
double WorkDays = 1 + ((End - Start).TotalDays * 5 - (Start.DayOfWeek - End.DayOfWeek) * 2) / 7;
if (End.DayOfWeek == DayOfWeek.Saturday) WorkDays--;
if (Start.DayOfWeek == DayOfWeek.Sunday) WorkDays--;
return WorkDays;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment