Date Calculation

Hey, just a simple question (but i got no answer in the online-help): I want to initialise two date variables with the first and the last day of the last month. How can i use CALCDATE for this purpose ? Stefan Weinreich Billing Analyst Edited by - StefanWeinreich on 2001 Sep 19 11:03:22

Hi Stefan, You can use CM (Current Month) to get the last day of the month. Use CM - 1M + 1D to get the first day. (CM = W1-version, in the German version it can be something else). Willy

I think the following date formulas will give you the required results: CALCDATE(’-1M-CM’, SomeDate); // First date of last month CALCDATE(’-1M+CM’, SomeDate); // Last date of last month Kind regards, Jan Hoek Weha Automatisering BV Woerden - The Netherlands

You better use CM + 1D - 1M. CM-1M+1D would be (30-09-01 - 1M = 30-08-01, +1D =) 31-08-01 as the first day. Willy P.S. Jan’s solution is more elegant. It will give you the first and last day of the month before the specified date. If you want the first and last day of the month from the specified date just use LastDay := CALCDATE(’+CM’,SomeDate); FirstDay := CALCDATE(’-CM’,SomeDate); Edited by - wex on 2001 Sep 19 11:32:16

Hey Willy, thanks, it works, but i had to change the term into: first of last month := CALCDATE(‘CM+1D-2M’, TODAY); last of last month := CALCDATE(‘CM+1D-1M-1D’, TODAY); especially the second term looks odd to me, but it works (current month + 1 day = next month - 1 month = first of this month - 1 day = last of last month). Can this term be styled better ? Ok, for the term runs correctly i could go on with the rest, but i want to understand how this function works… Stefan Weinreich Billing Analyst

‘-1M’ by definition returns a date in the previous month. ‘-CM’ and ‘CM’ in turn return the first and last day of a month. The combination of these two terms seems to me an elegant solution to your problem. Kind regards, Jan Hoek Weha Automatisering BV Woerden - The Netherlands

The CALCDATE function in Navision is very powerful, but it does take a bit to get used to. The attached FORM may help you as a tool to learn the function quicker. Its what I originaly used to come to grips with the function. download _________________________ David Singleton Navision Consultant since 1991 dmks22@home.com___________

Another way is as follows: RefDate := DMY2DATE(01,DATE2DMY(WORKDATE,2),DATE2DMY(WORKDATE,3)); // will give you the first day this month FirstDayLastMonth := CALCDATE (’-1M’,RefDate); LastDayLastMonth := CALCDATE(’-1D’,RefDate); :slight_smile: Regards fron California… – Alfonso Pertierra apertierra@teleline.es Spain Western Computer Los Angeles, California

thanks to all Interesting idea, Alfonso, although it doesn’t look more simple than my solution… Stefan Weinreich Billing Analyst