根据您是指实际周还是财政(财务)周,您可以使用这两个函数中的任何一个来为您计算:
财政周:
Function FiscalWeek(dtDate As Variant)
Dim dtFiscal As Date
Dim dtFstMon As Date
Dim i As Integer
'Ensure we are working with a valid date
If Not IsDate(dtDate) Then
FiscalWeek = "Invalid Date"
Exit Function
End If
'Strip out any timestamps
dtFiscal = DateSerial(Year(dtDate), Month(dtDate), Day(dtDate))
'Determine first Monday of April for given year
i = 1
Do Until Weekday(DateSerial(Year(dtFiscal), 4, i), 2) = 1
i = i + 1
Loop
dtFstMon = DateSerial(Year(dtFiscal), 4, i)
'Work out the difference in weeks from April for the relevant year
Select Case dtFiscal
Case Is < dtFstMon
FiscalWeek = DateDiff("WW", DateSerial(Year(dtFiscal) - 1, 4, 1), dtFiscal, 2)
Case Else
FiscalWeek = DateDiff("WW", DateSerial(Year(dtFiscal), 4, 1), dtFiscal, 2) + IIf(i = 1, 1, 0)
End Select
End Function
或实际周:
Function ActualWeek(dtDate As Variant)
Dim dtActual As Date
Dim dtFstMon As Date
Dim i As Integer
'Ensure we are working with a valid date
If Not IsDate(dtDate) Then
ActualWeek = "Invalid Date"
Exit Function
End If
'Strip out any timestamps
dtActual = DateSerial(Year(dtDate), Month(dtDate), Day(dtDate))
'Determine first Monday of January for given year
i = 1
Do Until Weekday(DateSerial(Year(dtActual), 1, i), 2) = 1
i = i + 1
Loop
dtFstMon = DateSerial(Year(dtActual), 1, i)
'Work out the difference in weeks from January for the relevant year
Select Case dtActual
Case Is < dtFstMon
ActualWeek = DateDiff("WW", DateSerial(Year(dtActual) - 1, 1, 1), dtActual, 2)
Case Else
ActualWeek = DateDiff("WW", DateSerial(Year(dtActual), 1, 1), dtActual, 2) + IIf(i = 1, 1, 0)
End Select
End Function