# Date Formula

**URL:** <https://www.dynamicsuser.net/t/date-formula/9586>\
**Category:** Developers Forum\
**Created:** [January 17, 2005, 5:30pm UTC](https://www.dynamicsuser.net/t/date-formula/9586 "2005-01-17T17:30:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mblauer](https://avatars.discourse-cdn.com/v4/letter/m/c67d28/32.png) [@mblauer](https://www.dynamicsuser.net/u/mblauer)\
**Post date:** [January 17, 2005, 5:30pm UTC](https://www.dynamicsuser.net/t/date-formula/9586/1 "2005-01-17T17:30:24Z")

</div>

Anyone help me with this I am attempting to simply list the start and end dates for the last 12 months? I get a time/date error message Thanks Y=Integer sd=code dim 12 ed=code dim 12 sd2=date dim12 ed2=date dim12 FOR Y:=1 TO 12 DO BEGIN sd[Y]:=’-[y]m-cm’; sd2[Y]:= CALCDATE(sd[Y]); ed[Y]:=’-[y]m+cm’; ed2[Y]:= CALCDATE(ed[Y]); END;

---

<div class="post-metadata">

**Author:** ![DjangMan](https://avatars.discourse-cdn.com/v4/letter/d/5e9695/32.png) [@DjangMan](https://www.dynamicsuser.net/u/DjangMan)\
**Post date:** [January 17, 2005, 6:28pm UTC](https://www.dynamicsuser.net/t/date-formula/9586/2 "2005-01-17T18:28:34Z")

</div>

The Date virtual table will get you all that without needing the CALCDATE stuff. From a quick codeunit: ` DateTable.SETFILTER("Period Type",'%1', DateTable."Period Type"::Month); DateTable.SETRANGE("Period Start",010105D,123105D); IF DateTable.FIND('-') THEN REPEAT MESSAGE('First Day: %1, Last Day: %2', DateTable."Period Start", NORMALDATE(DateTable."Period End")); UNTIL DateTable.NEXT = 0; ` Django

---

<div class="post-metadata">

**Author:** ![nilsm](https://avatars.discourse-cdn.com/v4/letter/n/82dd89/32.png) [@nilsm](https://www.dynamicsuser.net/u/nilsm)\
**Post date:** [January 17, 2005, 8:47pm UTC](https://www.dynamicsuser.net/t/date-formula/9586/3 "2005-01-17T20:47:24Z")

</div>

To answer your questions anyway … You assign a text to sd[Y] but C/AL does not replace the [Y] within you text with the actual integer value, your code should look like this sd[Y]:=’-’ + Y + ‘m-cm’; or a bit more elegant: sd[Y] := STRSUBSTNO(’-%1M-CM’,Y) Anyway, you should use Django’s suggestion that is much easier to handle… Saludos Nils
