ermittelt die Anzahl der Wochentage zwischen zwei Daten
private int CountWeekdays(DateTime startTime, DateTime endTime)
{
TimeSpan timeSpan = endTime - startTime;
DateTime dateTime;
int weekdays = 0;
for (int i = 0; i < timeSpan.Days; i++)
{
dateTime = startTime.AddDays(i);
if (IsWeekDay(dateTime))
weekdays++;
}
return weekdays;
}
private bool IsWeekDay(DateTime dateTime)
{
return ((dateTime.DayOfWeek != DayOfWeek.Saturday) && (dateTime.DayOfWeek != DayOfWeek.Sunday)
}
2 Kommentare zum Snippet