【问题标题】:How to get preivous month total count如何获得上个月的总数
【发布时间】:2012-01-27 11:18:46
【问题描述】:

我想获取上个月的总天数

代码

Dim period as string
period = '01/2011'
totdays = DateDiff("d", txtPeriod, DateAdd("m", 1, txtPeriod))

'这将给出该月的总天数...

但我想得到上个月的总天数

用户将只输入当前月份,但代码应验证上个月

预期输出

If period = '02/2011' means then it should display 31 days 'January
If period = '03/2011' means then it should display 28 days 'February

如何做到这一点...

任何帮助

【问题讨论】:

  • @JP 02/2011 仅 28 天,2012 仅 29 天....
  • 现在还是一月,我一直忘记现在是 2012 年。

标签: vb6


【解决方案1】:

这对我来说很好。还有,为什么你有一个变量period,却在你的计算中使用txtPeriod

Dim dt As Date
Dim DaysInMonth As Integer

dt = CDate(txtPeriod.Text)
dt = DateAdd("m", -1, dt)
DaysInMonth = DateDiff("d", dt, DateAdd("m", 1, dt))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-13
    • 1970-01-01
    • 1970-01-01
    • 2022-12-15
    相关资源
    最近更新 更多