访问 VBA 从月数中获取季度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26426648/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 04:53:44  来源:igfitidea点击:

Access VBA Get Quarter From Month Number

vbadatems-access

提问by user2294977

I am stuck in trying to find the quarter of year number from the month number i.e. i have month number 2 which should be quarter number 1, how do i do this in Access VBA or an access query? Thanks in advance.

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

回答by

You can use this function:

您可以使用此功能:

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

回答by Przemyslaw Remin

One liner for Excel:

Excel 的一个衬垫:

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

for SQL

用于 SQL

floor(([MonthNo]-1)/3) +1