双周日期 2011 VB6

发布于 2024-10-22 14:40:33 字数 990 浏览 0 评论 0原文

我试图在 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

大卫

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
    HardDate = 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撧情箌佬 2024-10-29 14:40:34

假设您知道 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文