如何获得上个月的总数

时间:2012-01-18 12:58:24

标签: vb6

我想获得上个月的总天数

代码

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

如何做到这一点......

任何帮助

1 个答案:

答案 0 :(得分:0)

这对我来说很好。另外,为什么你有变量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))