访问VBA从月份号获取季度

时间:2014-10-17 13:54:56

标签: vba date ms-access

我一直试图找到月份编号中的季度编号,即我有月份编号2应该是第1编号,我如何在Access VBA或访问查询中执行此操作? 提前谢谢。

2 个答案:

答案 0 :(得分:5)

您可以使用此功能:

Public Function Quarter(ByVal MonthNumber As Long) As Long

        If (MonthNumber < 1) Or (MonthNumber > 12) Then
                Call Err.Raise(6) ' Value out of Bounds '
        End If

        Let Quarter = (MonthNumber - 1) \ 3 + 1

End Function

答案 1 :(得分:0)

一个适用于Excel的班轮:

=INT((MonthNo-1)/3 +1)

对于SQL

floor(([MonthNo]-1)/3) +1
相关问题