# Calculating accounting year and month dates

**URL:** <https://www.dynamicsuser.net/t/calculating-accounting-year-and-month-dates/9675>\
**Category:** Developers Forum\
**Created:** [February 10, 2005, 3:41pm UTC](https://www.dynamicsuser.net/t/calculating-accounting-year-and-month-dates/9675 "2005-02-10T15:41:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SkippyKGS](https://avatars.discourse-cdn.com/v4/letter/s/5fc32e/32.png) [@SkippyKGS](https://www.dynamicsuser.net/u/SkippyKGS)\
**Post date:** [February 10, 2005, 3:41pm UTC](https://www.dynamicsuser.net/t/calculating-accounting-year-and-month-dates/9675/1 "2005-02-10T15:41:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![David](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@David](https://www.dynamicsuser.net/u/David)\
**Post date:** [February 10, 2005, 4:18pm UTC](https://www.dynamicsuser.net/t/calculating-accounting-year-and-month-dates/9675/2 "2005-02-10T16:18:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![greg0ry](https://avatars.discourse-cdn.com/v4/letter/g/d07c76/32.png) [@greg0ry](https://www.dynamicsuser.net/u/greg0ry)\
**Post date:** [February 11, 2005, 8:19am UTC](https://www.dynamicsuser.net/t/calculating-accounting-year-and-month-dates/9675/3 "2005-02-11T08:19:26Z")

</div>

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(’-’)

---

<div class="post-metadata">

**Author:** ![SkippyKGS](https://avatars.discourse-cdn.com/v4/letter/s/5fc32e/32.png) [@SkippyKGS](https://www.dynamicsuser.net/u/SkippyKGS)\
**Post date:** [February 11, 2005, 10:11am UTC](https://www.dynamicsuser.net/t/calculating-accounting-year-and-month-dates/9675/4 "2005-02-11T10:11:35Z")

</div>

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
