本示例取得一个日期,并使用 DateAdd 函数显示指定月份数以后的相应日期。 Dim Msg, Number, StartDate As String 'Declare variables. Dim Months As Double Dim SecondDate As Date Dim IntervalType As DateInterval IntervalType = DateInterval.Month ' Specifies months as interval. StartDate = InputBox("Enter a date") SecondDate = CDate(StartDate) Number = InputBox("Enter number of months to add") Months = Val(Number) Msg = "New date: " & DateAdd(IntervalType, Months, SecondDate) MsgBox (Msg)
Private Sub Command1_Click() a = DateAdd("m", -1, Date) MsgBox "上月:" + Format(a, "yyyy年mm月") a = Format(Date, "Long Date") MsgBox "长日期:" + CStr(a) End Sub
Dim Msg, Number, StartDate As String 'Declare variables.
Dim Months As Double
Dim SecondDate As Date
Dim IntervalType As DateInterval
IntervalType = DateInterval.Month ' Specifies months as interval.
StartDate = InputBox("Enter a date")
SecondDate = CDate(StartDate)
Number = InputBox("Enter number of months to add")
Months = Val(Number)
Msg = "New date: " & DateAdd(IntervalType, Months, SecondDate)
MsgBox (Msg)
msgbox "上个月是:" & a
MyStr = Format(Date, "Long Date")
a = DateAdd("m", -1, Date)
MsgBox "上月:" + Format(a, "yyyy年mm月")
a = Format(Date, "Long Date")
MsgBox "长日期:" + CStr(a)
End Sub