当需要求当季的一个数量时,这两个函数会用得上;
以下函数求得当季的第一天与最后一天:
Function FirstDayInQuarter(Optional dtmDate As Date = 0) As Date
If dtmDate = 0 Then
dtmDate = Date
End If
FirstDayInQuarter = DateSerial(Year(dtmDate), Int((Month(dtmDate) - 1) / 3) * 3 + 1, 1)
End Function
Function LastDayInQuarter(Optional dtmDate As Date = 0) As Date
If dtmDate = 0 Then
dtmDate = Date
End If
LastDayInQuarter = DateSerial(Year(dtmDate), Int((Month(dtmDate) - 1) / 3) * 3 + 4, 0)
End Function
附 件:
点击下载此附件
图 示: