我正在试图弄清楚如何做到这一点。一直在做研究,找不到任何东西,我可以弄清楚如何使用。
我有一个startdate,enddate,recurringday,customer
startdate = 04/01/2013
enddate = 04/30/2013
customer = john
recurringday =星期一
我想在startdate和enddate的每个星期一为john插入一条记录,有人可以帮帮我吗?新的vb.net
由于
答案 0 :(得分:0)
使用DayofWeek功能检查今天是星期一。然后使用Insert命令。
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
答案 1 :(得分:0)
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
答案 2 :(得分:0)
试试这个。
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