SUMMARY
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.
back to the top
Using an Expression to Get the Fiscal Year or Fiscal Month
NOTE: This section applies only to a Microsoft Access database (.mdb).
To get the fiscal year or fiscal month of a particular date by using an
expression, follow these steps:
- Open the sample database Northwind.mdb.
- Create the following new query based on the Orders table.
NOTE: In the following sample expressions, an underscore (_) at the end of a line is used as a line-continuation character. Remove the underscore from the end of the line when re-creating these sample expressions.
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
- Run the query, and then scroll through the query datasheet. Note that the fiscal year and fiscal month appear for each record in the Orders table.
You can use the FYear and FMonth expressions in your database by modifying the Date field, the day and the month, to the appropriate
values for your fiscal year. For example, if the fiscal year begins on 9/15
of the current calendar year, you can modify the previous expressions as
follows:
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
back to the top
Using Sample Functions to Get the Fiscal Year or Fiscal Month
NOTE: This section applies to a Microsoft Access database (.mdb) and a Microsoft Access project (.adp).
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
To get the fiscal year or fiscal month of a particular date by using user defined functions, follow these steps:
- Create a module and type the following lines in the Declarations section:
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.
- Type the following two procedures:
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
- To test these functions, type each of the following lines in the Immediate window, and then press ENTER after each one:
?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.
back to the top
REFERENCES
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.
back to the top