Sei sulla pagina 1di 4

HOW TO: Get the Fiscal Year or Month of a Particular Date in Access 2000 Page 1 of 4

Article ID: 210249 - Last Review: October 11, 2006 - Revision: 2.2
HOW TO: Get the Fiscal Year or Month of a Particular Date in Access
2000
This article was previously published under 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.

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:

1. Open the sample database Northwind.mdb.


2. 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

3. 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

http://support.microsoft.com/kb/210249 13/04/2009
HOW TO: Get the Fiscal Year or Month of a Particular Date in Access 2000 Page 2 of 4

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

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:

1. 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.

2. 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

http://support.microsoft.com/kb/210249 13/04/2009
HOW TO: Get the Fiscal Year or Month of a Particular Date in Access 2000 Page 3 of 4

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

3. 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.

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.

APPLIES TO

 Microsoft Access 2000 Standard Edition

Keywords: kbdta kbhowto kbhowtomaster kbofficeprog kbprogramming


KB210249

Get Help Now

http://support.microsoft.com/kb/210249 13/04/2009
HOW TO: Get the Fiscal Year or Month of a Particular Date in Access 2000 Page 4 of 4

Get Help Now


Contact a support professional by E-mail, Online, or Phone

Help and Support ©2009 Microsoft

http://support.microsoft.com/kb/210249 13/04/2009

Potrebbero piacerti anche