# How to Calculate the Current Fiscal Year

In Navision, there's no function that will give you the fiscal year according to what you've setup on the Accounting Period table. Here's a code that will get the current fiscal year based on the accounting period:

AccountingPeriod is a record variable  to table 50
Date1 and Date2 are date variables

AccountingPeriod.RESET;
AccountingPeriod.SETRANGE("New Fiscal Year",TRUE);
AccountingPeriod."Starting Date" := WORKDATE;
AccountingPeriod.FIND('=<');
Date1 := AccountingPeriod."Starting Date";
IF AccountingPeriod.NEXT = 0 THEN
Date2 := 12319999D
ELSE
Date2 := AccountingPeriod."Starting Date" - 1;

Comment List
• Mark: Codeunit 1 is too complicated if you just need a simple calculation. I extracted the key areas so users can easily understand what needs to be done.

Erik: Y works on date filters, but if you need to get specific dates using Calcdate function, it won't work.

• And what happened to just entering "Y"?

• What about the function in Codeunit 1?

FindPeriod(Date1,Date2,FindYear,DateFilterText,Position,Length)

IF FindYear THEN

AccountingPeriod.SETRANGE("New Fiscal Year",TRUE)

ELSE

AccountingPeriod.SETRANGE("New Fiscal Year");

Sign := '';

Sign := '+'

ELSE

Sign := '-';

IF Sign = '' THEN

IF ReadNumeral(Numeral,DateFilterText,Position,Length) THEN BEGIN

IF FindYear THEN

AccountingPeriod.FINDFIRST

ELSE BEGIN

AccountingPeriod.SETRANGE("New Fiscal Year",TRUE);

AccountingPeriod."Starting Date" := WORKDATE;

AccountingPeriod.FIND('=<');

AccountingPeriod.SETRANGE("New Fiscal Year");

END;

AccountingPeriod.NEXT(Numeral - 1);

END ELSE BEGIN

AccountingPeriod."Starting Date" := WORKDATE;

AccountingPeriod.FIND('=<');

END

ELSE BEGIN

IF NOT ReadNumeral(Numeral,DateFilterText,Position,Length) THEN

EXIT(Position);

IF Sign = '-' THEN

Numeral := -Numeral;

AccountingPeriod."Starting Date" := WORKDATE;

AccountingPeriod.FIND('=<');

AccountingPeriod.NEXT(Numeral);

END;

Date1 := AccountingPeriod."Starting Date";

IF AccountingPeriod.NEXT = 0 THEN

Date2 := 31129999D

ELSE

Date2 := AccountingPeriod."Starting Date" - 1;