I am trying to loop to get all 2011 bi-weekly dates using this code in VB6:
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
Har开发者_JAVA技巧dDate = DateAdd("d", 1, nextpayday)
DateToday = DateAdd("d", 10, HardDate)
x = x + 1
Loop
However, using that code above does not produce an on going bi-weekly date...
Any help would be great!
date example
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
David
Assuming you know the first date you want in 2011, and you know you want 26 fortnights, the code can be simplified extremely. For illustration purposes, add a textbox "Text1" to a form, and set MultiLine = True in the designer. We'll use 1/7/2011 for our starting date:
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
The output that shows in the textbox looks like this:
1/7/2011
1/21/2011
2/4/2011
2/18/2011
3/4/2011
...
12/23/2011
精彩评论