所以我需要知道如何从星期五的日期开始每隔一个星期五,让程序检查日期是否是其中一个日期,如果是,那么X功能是否正常。到目前为止,我发现如何在一个星期五之后找到星期五,但我需要它来收集日期并保存它们然后检查它们。
Dim payday as Date= GetNext(DayOfWeek.Friday)
Function GetNext(ByVal d As DayOfWeek, Optional ByVal StartDate As Date = Nothing) As Date
If StartDate = DateTime.MinValue Then StartDate = Now
For p As Integer = 1 To 7
If StartDate.AddDays(p).DayOfWeek = d Then Return StartDate.AddDays(p)
Next
End Function
然后这是我正在考虑的If语句
If Date.Today = payday Then
'do this
End If
我正在思考的粗略草图。
答案 0 :(得分:3)
Dim startDate As Date 'fill with an initial Friday
Function IsPayday(Optional dte as Date? = Nothing) As Boolean
dte = If(dte, Today)
Return DateDiff(DateInterval.Day, startDate, dte) Mod 14 = 0
End Function
并使用它:
Dim yesterday = Today.AddDays(-1)
If IsPayday(yesterday) Then
'yesterday was a pay day
End If
If IsPayday() Then
'today is a pay day
End If