我正在尝试循环使用VB6中的此代码获取所有2011年双周日期:
Dim HardDate As Date
Dim NumberOfDaysSince As Integer
Dim modulus As Integer
Dim DaysToNext As Integer
Dim nextpayday As Date
Dim x As Integer
x = 1
DateToday = Date
HardDate = Format(Now, "m/dd/yyyy")
Do While x <> 20
NumberOfDaysSince = DateDiff("d", HardDate, DateToday)
modulus = NumberOfDaysSince Mod 14
DaysToNext = 15 - modulus
nextpayday = Date + DaysToNext
Debug.Print nextpayday
HardDate = DateAdd("d", 1, nextpayday)
DateToday = DateAdd("d", 10, HardDate)
x = x + 1
Loop
但是,使用上面的代码不会产生正在进行的双周日期......
任何帮助都会很棒!
日期示例
Pay Begin Date | Pay End Date | Check Date | Posts
-------------------------------------------------------------------
1/14/2011 | 1/24/2011 | 2/10/2011 | 2/3/2011
1/28/2011 | 2/10/2011 | 2/24/2011 | 2/17/2011
2/11/2011 | 2/24/2011 | 3/10/2011 | 3/3/2011
大卫
答案 0 :(得分:1)
假设您知道2011年的第一个日期,并且您知道您想要26个四分之一的夜晚,那么代码可以非常简化。为了便于说明,将一个文本框“Text1”添加到表单中,并在设计器中设置MultiLine = True。我们将使用1/7/2011作为开始日期:
Dim HardDate As Date
Dim x As Integer
x = 1
HardDate = "1/7/2011"
Text1.Text = HardDate
Do Until x = 26
HardDate = DateAdd("d", 14, HardDate)
Text1.Text = Text1.Text & vbCrLf & HardDate
x = x + 1
Loop
文本框中显示的输出如下所示:
1/7/2011
1/21/2011
2/4/2011
2/18/2011
3/4/2011
...
12/23/2011