fy - Fiscal Year

Prev Next

Function Names

fy

Description

This function identifies the financial (or fiscal) year of the date provided. If 2 parameters (date and month year ending) are provided, then the financial year will be returned as a 4-digit numeral. Example: fy( "2022-04-01", 3 ) returns 2022. If a formatting string is provided, then the returned value is a string which contains either one year or the combination of two years. The format pattern string will be checked for pound '#' characters. Following rules apply:

  • If one contiguous set of 2 '#' characters is identified, then these symbols will be replaced by the last two digits of the ending year
  • If one contiguous set of 4 '#' characters is identified, then these symbols will be replaced by the last four digits of the ending year
  • If one single '#' character is identified, then the quarter inside the financial year will be returned. Example: For years ending in March, then February is considered to be in the 4th quarter.
  • Any other number of contiguous '#' characters, or a 3rd set of 2 or 4 '#' characters remain unchanged.
  • Any other character is treated as being part of the string to be returned, e.g. "FY ####-##" returns "FY 2020-21".
  • In case the month specified equals twelve, then the starting and ending years are obviously the same.

If a blank date is provided, then 0 is returned in case no format pattern string is provided, otherwise a blank string is returned.

Call as: function

Restrictions

Indirect parameter passing is disabled

Parameter count

2-3

Parameters

No.TypeDescription
1
input
date or string converted to date Date

Value to extract as described above

2
input
numeral Month year ending

Specify the last month of the financial year (Example: Specify 3 for fiscal years ending on 31. March every year). Value must be between 1 and 12.

Opt. 3
input
string Format pattern

If a formatting string is provided, then the financial year will be returend as a string and not as a number.

Default value: A numeric 4-digit year will be returned.

Return value

TypeDescription
numeral
string
Result

Numeric 4-digit year if 2 parameters are provided, or string result if 3 parameters including the format pattern are provided.

Examples

  date[] = "2022-05-01";
  echo( "Date is ", date[] );
  patterns[] = { "FY ##", "####/##", "Q# FY ##-##" };

  for (month[]=1, month[]<=12, month[]++ )
  {
      echo( "Year ending in ", str( date(2022,month[],1),"Mmmm" ), ": " );
      print( "    FY: ", fy( date[], month[] ) );
      for all parameters( patterns[], pattern[] )
      {
      print("    ", fy( date[], month[], pattern[] ) );
      }
      echo;
  }

Output

Date is 2022-05-01
Year ending in January:
    FY: 2023    FY 23    2022/23    Q2 FY 22-23
Year ending in February:
    FY: 2023    FY 23    2022/23    Q1 FY 22-23
Year ending in March:
    FY: 2023    FY 23    2022/23    Q1 FY 22-23
Year ending in April:
    FY: 2023    FY 23    2022/23    Q1 FY 22-23
Year ending in May:
    FY: 2022    FY 22    2021/22    Q4 FY 21-22
Year ending in June:
    FY: 2022    FY 22    2021/22    Q4 FY 21-22
Year ending in July:
    FY: 2022    FY 22    2021/22    Q4 FY 21-22
Year ending in August:
    FY: 2022    FY 22    2021/22    Q3 FY 21-22
Year ending in September:
    FY: 2022    FY 22    2021/22    Q3 FY 21-22
Year ending in October:
    FY: 2022    FY 22    2021/22    Q3 FY 21-22
Year ending in November:
    FY: 2022    FY 22    2021/22    Q2 FY 21-22
Year ending in December:
    FY: 2022    FY 22    2022/22    Q2 FY 22-22
Try it yourself: Open LIB_Function_fy.b4p in B4P_Examples.zip. Decompress before use.

See also

year
fq