给定一个4-5-4日历和日期,我怎么确定哪些财政周该日期落在?(Given a 4-5-4 cale

2019-10-23 09:24发布

我们有一个4-5-4日历中的会计年度为公历二月星期日。 对于FY 2016年,第一天居然是在1 - 今天是星期天,1月31日。

我需要编写一个函数,它接受一个日期作为输入,并返回财政一周,如201552,这将是2015财年的第52届财政周。

我认为第一步是搞清楚输入日期的财年开始的第一天。 我知道,它总是一个周日,但我怎么知道它是否是第一个星期天日历月,或最后一个星期日历一月?

(幸运的是这个功能的目的,我可以忽略偶尔的第53周,我就可以回到第52周时这种情况下,这是因为(我说),其具有53财星期年是不可预测的(在这家公司反正)和被确定。人类心血来潮。)

有什么建议么?

更新:

我已经通过FY2017给出FY日历文件为公司2005年度从。 我看到的模式是:

  • 如果2月1日是周一,周二,周三或,然后FY的第一天是一月份的最后一个星期日。
  • 如果2月1日是周四,周五,周六或周日,则财年第一天是2月的第一个星期日。

我认为这给了我什么,我需要。

Answer 1:

我认为第一步是要找到周为输入日期的年的2月1日这一天。

接下来,找到财年,这是基于周的那2月1日的第一天。 如果它是一个星期一,星期二,星期三或者,然后FY的第一天是一月份的最后一个星期日。 否则,FY的第一天是一月份的第一个星期日。

接着,确定输入日期是否处于FY或之前的一个。

然后,如果输入的日期是在之前的财政年度,获取财年的第一天。

接下来,从财年的第一天算日子,到输入日期的天。 由7划分,舍入到下一个整数。 这是FY一周。

在这一点上,我就知道了输入日期的财年和FY星期,可以退货。

更新:

这里是我有; 它在我的测试:

Public Function ConvertDateToRawFYWeek(convert_date As Date) As String
'Fiscal year starts on either:
    'the last Sunday in January (if Feb 1st is a Mon, Tue, or Wed), OR:
    'the first Sunday in February (if Feb 1st is Thur, Fri, Sat, or Sun).

    Dim iCalendarYearOfInputDate As Long, iInputMonth As Long, iInputDay As Long, iTmpYear As Long
    Dim iFebFirstOfTmpYear As Long, strFebFirstWeekdayOfTmpYear As String
    Dim iFirstDayofFYOfTmpYear As Long
    Dim iFiscalYearOfInputDate As Long
    Dim iDayOfInputDate As Long
    Dim iDayOfFY As Long, iWeekOfFY As Long, strWeekOfFY As String
    Dim bDone As Boolean

    iCalendarYearOfInputDate = Year(convert_date)
    iInputMonth = Month(convert_date)
    iInputDay = Day(convert_date)
    iDayOfInputDate = CLng(DateValue(convert_date))


    bDone = False 'init.
    iTmpYear = iCalendarYearOfInputDate 'init.
    Do

            '***get the day of the week of feb 1st of tmp date's year:
            iFebFirstOfTmpYear = DateSerial(iTmpYear, 2, 1)
            strFebFirstWeekdayOfTmpYear = Format(iFebFirstOfTmpYear, "DDDD")

            '***get the first day of the FY of the tmp date's year:
            Select Case strFebFirstWeekdayOfTmpYear
                Case "Monday"
                    'first day of the tmp year's FY is the last Sunday of January, which for the tmp year is Jan 31st:
                    iFirstDayofFYOfTmpYear = iFebFirstOfTmpYear - 1
                Case "Tuesday"
                    'first day of the tmp year's FY is the last Sunday of January, which for the tmp year is Jan 30th:
                    iFirstDayofFYOfTmpYear = iFebFirstOfTmpYear - 2
                Case "Wednesday"
                    'first day of the tmp year's FY is the last Sunday of January, which for the tmp year is Jan 29th:
                    iFirstDayofFYOfTmpYear = iFebFirstOfTmpYear - 3
                Case "Thursday"
                    'first day of the tmp year's FY is the first Sunday of February, which for the tmp year is Feb 4th:
                    iFirstDayofFYOfTmpYear = iFebFirstOfTmpYear + 3
                Case "Friday"
                    'first day of the tmp year's FY is the first Sunday of February, which for the tmp year is Feb 3rd:
                    iFirstDayofFYOfTmpYear = iFebFirstOfTmpYear + 2
                Case "Saturday"
                    'first day of the tmp year's FY is the first Sunday of February, which for the tmp year is Feb 2nd:
                    iFirstDayofFYOfTmpYear = iFebFirstOfTmpYear + 1
                Case "Sunday"
                    'first day of the tmp year's FY is the first Sunday of February, which for the tmp year is Feb 1st:
                    iFirstDayofFYOfTmpYear = iFebFirstOfTmpYear
            End Select

            '***get the fiscal year of the input date:
            If iDayOfInputDate >= iFirstDayofFYOfTmpYear Then
                iFiscalYearOfInputDate = iTmpYear
                bDone = True
            Else
                iTmpYear = iTmpYear - 1 'loop again.
            End If

    Loop Until bDone


    '***count the days from that first day of the FY, to the day of the input date.
    'Divide by 7, rounding UP to the next integer. That is the FY week.
    iDayOfFY = iDayOfInputDate - iFirstDayofFYOfTmpYear
    iWeekOfFY = Round((iDayOfFY / 7) + 0.50000000000001) 'round up to next integer.
    strWeekOfFY = Format(iWeekOfFY, "00")

    strFY = Format(iTmpYear, "0000")

    ConvertDateToRawFYWeek = strFY & strWeekOfFY

End Function


文章来源: Given a 4-5-4 calendar and a date, how do I determine what fiscal week that date falls in?