ACC2000: How to Get the Fiscal Year or Month of a Particular DateID: q210249
|
This article shows you how to get the fiscal year or fiscal month of a particular date by using an expression or a user-defined function.
Query: GetFiscalDates
-------------------------------------------------------------------
Field: OrderDate
Table: Orders
Criteria: DatePart("yyyy",[OrderDate])=1997
Field: FYear: Year([OrderDate])-IIf([OrderDate]< _
DateSerial(Year([OrderDate]),6,16),1,0)
Field: FMonth: (Month([OrderDate])+IIf(Day([OrderDate])<16,6,7)-1) _
Mod 12+1
Field: FYear: Year([FieldName])-IIf([FieldName]< _
DateSerial(Year([FieldName]),9,15),1,0)
Field: FMonth: (Month([FieldName])+IIf(Day([FieldName])<15,9,10)-1) _
Mod 12+1
If the fiscal year begins on 9/15 of the previous calendar year, you can
modify the FYear expression as follows:
Field: FYear: Year([FieldName])-IIf([FieldName]< _
DateSerial(Year([FieldName]),9,15),1,0)+1
http://www.microsoft.com/mcsp/For more information about the support options available from Microsoft, please see the following page on the World Wide Web:
http://www.microsoft.com/support/supportnet/overview/overview.aspTo get the fiscal year or fiscal month of a particular date by using user defined functions, follow these steps:
Option Explicit
Const FMonthStart = 6 ' Numeric value representing the first month
' of the fiscal year.
Const FDayStart = 16 ' Numeric value representing the first day of
' the fiscal year.
Const FYearOffset = -1 ' 0 means the fiscal year starts in the
' current calendar year.
' -1 means the fiscal year starts in the
' previous calendar year.
Function GetFiscalYear(ByVal x As Variant)
If x < DateSerial(Year(x), FMonthStart, FDayStart) Then
GetFiscalYear = Year(x) - FYearOffset - 1
Else
GetFiscalYear = Year(x) - FYearOffset
End If
End Function
Function GetFiscalMonth(ByVal x As Variant)
Dim m
m = Month(x) - FMonthStart + 1
If Day(x) < FDayStart Then m = m - 1
If m < 1 Then m = m + 12
GetFiscalMonth = m
End Function
?GetFiscalYear(#7/1/1999#)
Note that this line returns the year 2000.
?GetFiscalMonth(#8/1/1999#)
Note that this line returns the number 2. The 2 represents the second month in the fiscal year.For more information about the DateSerial function, click Microsoft Access Help on the
Help menu, type "DateSerial, Day, Month, and Year function examples" in the Office Assistant or the Answer Wizard,
and then click Search to view the topic.
Additional query words:
Keywords : kbprg kbdta AccCon
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: July 6, 1999