用户可以在表单中选择开始日期和结束日期。 (比如星期一到星期一。) 如何检查当前工作日是否在这两个工作日之间?
Dim WEstart As DayOfWeek = 5 'Friday
Dim WEend As DayOfWeek = 1 'Monday
If Date.Now.DayOfWeek >= WEstart And Date.Now.DayOfWeek <= WEend Then
Return True
Else
Return False
End If
无效。
答案 0 :(得分:2)
试试看。这将检查星期五和星期一之间的天数。也就是说,它在周五,周六,周日和周一返回“真”。
如果星期几是星期二,星期三或星期四,则返回false。
Dim startday As DayOfWeek = DayOfWeek.Friday
Dim endday As DayOfWeek = DayOfWeek.Sunday
Dim today As DayOfWeek = DateTime.Now.DayOfWeek
If endday >= startday Then
Return (today >= startday AndAlso today <= endday)
Else
Return (today >= startday OrElse today <= endday)
End If
答案 1 :(得分:0)
这似乎对我有用:
Sub Main()
Debug.WriteLine(IsBetween(Now, DayOfWeek.Monday, DayOfWeek.Friday))
End Sub
Function IsBetween(vDate As DateTime, startDay As DayOfWeek, endDay As DayOfWeek)
If startDay <= endDay Then Return vDate.DayOfWeek >= startDay And
vDate.DayOfWeek <= endDay
Return vDate.DayOfWeek <= endDay Or vDate.DayOfWeek >= startDay
End Function