Calculating accounting year and month dates

Can anybody give me a clue as to how, programatically, to calculate the accounting period month and year that a given date falls into. e.g. if the accounting year starts on 1st Oct, then today’s year start will be 1/10/04 and ends 30/9/04 and similarly with month. I’ve experimented with calcdate(CM) etc but that works with calendar years. I presume I need some interaction with the accounting period table. To this end I tried entering the following code; Date := TODAY; AccPeriodRec.SETFILTER(“Period Type”,‘Month’); AccPeriodRec.SETFILTER(“Period Start”,’<=Date’); AccPeriodRec.SETFILTER(“Period End”,’>=Date’); AccPeriodRec.Get which compiles, but when I run it gives me a message “Date is not a valid date”, which surprised me. Any suggestions would be appreciated.

Date := TODAY; AccPeriodRec.SETCURRENTKEY("Starting Date"); AccPeriodRec.SETRANGE("Starting Date", 0D, Date); IF AccPeriodRec.FIND('+') THEN // the latest Start Date <= given date MESSAGE('Month: %1, Year: %2. ', DATE2DMY(AccPeriodRec."Starting Date", 2), DATE2DMY(AccPeriodRec."Starting Date", 3)) ELSE ERROR('Accounting Period not found.'); You can also give a look at Item Availability by Period or codeunit 359 - PeriodFormManagement.

there is an error in your code: Date := TODAY; AccPeriodRec.SETFILTER(“Period Type”,‘Month’); AccPeriodRec.SETFILTER(“Period Start”,’<=Date’); AccPeriodRec.SETFILTER(“Period End”,’>=Date’); AccPeriodRec.Get it should be like this: Date := TODAY; AccPeriodRec.SETFILTER(“Period Type”,‘Month’); AccPeriodRec.SETFILTER(“Period Start”,’<=%1’,Date); AccPeriodRec.SETFILTER(“Period End”,’>=%1’,Date); AccPeriodRec.FIND(’-’)

Thanks for the replies. I implemented David’s suggestion because it was the first I received, but it doesn’t surprise me there was a bug in the original code. I thought it was on the right lines Thanks again