enter image description here如何计算某一天到没有假期的某一天以及周六,周日(VB)使用日期时间选择器
离开人员系统 请帮帮我!
从图片中可以看出来 左边是日期开始,右边是结束日期 然后,如果我选择日期。然后在文本框上计算一天...没有星期六星期六和假日在Access数据库...答案 0 :(得分:0)
从开始到结束计算不是周六或周日的天数:
Dim startDate As Date = New DateTime(2016, 1, 1)
Dim endDate As Date = DateTime.Now
Dim currentDate = startDate
Dim daysWithoutSatOrSun As Integer = 0
Do
If currentDate.DayOfWeek <> DayOfWeek.Saturday AndAlso currentDate.DayOfWeek <> DayOfWeek.Sunday Then
daysWithoutSatOrSun += 1
End If
currentDate = currentDate.AddDays(1)
Loop Until currentDate > endDate
MessageBox.Show("Days " & daysWithoutSatOrSun)
答案 1 :(得分:0)
一个可读选项是使用LINQ:
Dim days As Int32 = (d2 - d1).Days
Dim weekend = {DayOfWeek.Saturday, DayOfWeek.Sunday }
Dim nonWeekendDays = From d in Enumerable.Range(0, days + 1)
Select day = d1.Date.AddDays(d)
Where Not weekend.Contains(day.DayOfWeek)
Dim countOfDays As Int32 = nonWeekendDays.Count()
如果您的List(Of Date)
包含可以添加的假期:
Where Not weekend.Contains(day.DayOfWeek) AndAlso Not holidays.Contains(day)