我试图弄清楚如何做到这一点。一直在研究,找不到任何我可以弄清楚如何使用的东西。
我有一个开始日期、结束日期、重复日期、客户
开始日期 = 04/01/2013
结束日期 = 04/30/2013
客户 = 约翰
重复日=星期一
我想在每个星期一的 startdate 和 enddate 内为 john 插入一条记录,有人可以帮我吗?vb.net 的新手
谢谢
使用 DayofWeek 函数检查今天是否是星期一。然后使用插入命令。
Dim startdate As DateTime = Convert.ToDateTime("01 Apr 2013")
Dim enddate As DateTime = Convert.ToDateTime("30 Apr 2013")
Dim DofW = Now.DayOfWeek()
dim recurringday = "Monday"
If now >= startdate And now <= enddate Then
If DofW = recurringday Then
'Insert Record
End If
End If
@Sweety 建议使用 .DayofWeek,但我不确定他的方法是否满足您的要求。尝试这个:
Dim StartDate As DateTime = CDate("01 Apr 2013")
Dim FinishDate As DateTime = CDate("30 Apr 2013")
Dim RecurringDay = "Monday"
Dim Period = FinishDate.Subtract(StartDate).TotalDays
Dim CurrentDate As DateTime
For Counter As Integer = 0 To Period
CurrentDate = StartDate.AddDays(Counter)
If CurrentDate.DayOfWeek = RecurringDay Then
'Insert Record
End If
Next
尝试这个。
Dim StartDate As DateTime = #4/1/2013#
Dim FinishDate As DateTime = #4/30/2013#
Dim RecurringDay As Integer = DayOfWeek.Monday
'force to first RecurringDay
If RecurringDay < StartDate.DayOfWeek Then StartDate = StartDate.AddDays(7)
StartDate = StartDate.AddDays(RecurringDay - StartDate.DayOfWeek)
Do While StartDate <= FinishDate
Debug.WriteLine(StartDate.ToLongDateString)
'insert record
StartDate = StartDate.AddDays(7)
Loop