I think the first step is to find the day of the week for Feb 1st of the input date's year.
Next, find the first day of the FY, which is based on that Feb 1st day of week. If it's a Mon, Tue, or Wed, then first day of FY is last Sunday of January. Otherwise, first day of FY is first Sunday of January.
Next, determine whether the input date is in that FY or the one before.
Then, if the input date is in the previous FY, get the first day of that FY.
Next, 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.
At that point, I'll know the input date's FY year and FY week, and can return it.
UPDATE:
Here's what I have; it works in my tests:
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
weeknum()
( : – p._phidot_