VBA 学习笔记2 - 时间操作的例子
2020-02-20 本文已影响0人
赵阳_c149
取得当前时间
Dim currentDate As Date
currentDate = Now()
取得上个月的天数
Function getNumOfDaysInLastMonth(ByVal targetDate As Date) As Integer
' get the num of days in the last month of target date
Dim currentYear As Integer
Dim currentMonth As Integer
Dim firstDayOfCurrentMonth As Date
currentYear = Year(targetDate)
currentMonth = Month(targetDate)
firstDayOfCurrentMonth = CDate(currentYear & "-" & currentMonth & "-1")
firstDayOfLastMonth = DateAdd("m", -1, firstDayOfCurrentMonth)
getNumOfDaysInLastMonth = DateDiff("d", firstDayOfLastMonth, firstDayOfCurrentMonth)
End Function
参考
时间函数