Microsoft Dynamics NAV – How To: Find Start Date and End Date of Previous Month

“——————————————————————————————————————————————————

Support translation: http://amzn.to/1Z7d5oc
——————————————————————————————————————————————————
Microsoft Dynamics NAV – How To: Find Start Date and End Date of Previous Month

Local/Global Variables:

Name DataType Subtype Length
StartDate Date
EndDate Date

StartDate = Starting date of last month.
EndDate = Last day of last month.
StartDate := CALCDATE(‘<-CM-1M>’); //StartDate = 01/08/2012
EndDate := CALCDATE(‘CM’,StartDate); //EndDate = 31/08/2012.
CALCDATE

From Microsoft Dynamics NAV 2009 R2 Help.
Calculates a new date that is based on a date expression and a reference date.
NewDate := CALCDATE(DateExpression [, Date])
Parameters
DateExpression
Type: Text, Code, or DateFormula
The date expression can be any length. The string is interpreted from left to right with one subexpression at a time. The following rules describe the valid syntax of date expressions:
· DateExpression = [<SubExpression>][<SubExpression>][<SubExpression>]
· <SubExpression> = [<Sign>] <Term>
· <Sign> = + | –
· <Term> = <Number><Unit> | <Unit><Number> | <Prefix><Unit>
· <Number> = Positive integer
· <Unit> = D | WD | W | M | Q | Y (D=day, WD=weekday, W=week, M=month, Q=quarter, Y=year)
· <Prefix> = C (C=current)
These production rules show that date expressions consist of zero, one, two, or three subexpressions. Each subexpression comprises an optional sign and a term. The following are some typical examples of terms:
· 30D (30 days; corresponds to <Number><Unit>)
· WD2 (weekday number 2; corresponds to <Unit><Number>)
· CW (current week; corresponds to <Prefix><Unit>)
The internal calendar of C/SIDE starts on Monday and ends on Sunday. This means that Monday is weekday 1 and Sunday is weekday 7.
A run-time error occurs if the syntax of DateExpression is incorrect.
Date
Type: Date
Use this optional parameter to define a reference date. The default is the current system date.
If you omit this optional value the current system date is used.

Property Value/Return Value
Type: Date
The date that is computed from the reference date and the date expression.

Remarks
DateExpression can be a field or variable of type Text or Code, and it can be a field or variable of type DATEFORMULA. The benefit of using a DateFormula field or variable is that the date formula becomes language independent.
The user can enter formulas in the currently selected language. The formula is stored in a generic format in a field or variable. When the formula needs to be displayed, the actual string that is displayed is converted to the currently selected language.
For example, if a user with language set to ENG (English) enters the date formula “”1W+1D”” for one week and one day, then a user with the language set to FRA (French) sees “”1S+1J,”” and a user with the language set to ESP (Spanish) sees “”1S+1D””.
If a date formula is entered with < > delimiters surrounding it, then the date formula is stored in a generic, nonlanguage-dependent format. This makes it possible to develop date formulas that are not dependent on the currently selected language.
For more information about calculating the duration between two DateTimes, see Duration Data Type.

Example 1

This code example shows how to use the production rules that were previously described.
Copy Code
<CQ+1M-10D>
This should be interpreted as the following: current quarter + 1 month – 10 days.
The DateExpression is composed of the following:
<Prefix><Unit><Sign><Number><Unit><Sign><Number><Unit>
Note
The angle brackets (< >) specify that the expression is not translated, regardless of the application language. For more information about multilanguage capabilities with date formulas, see Developing Multilanguage-Enabled Applications.

Example 2

This example shows how to use the CALCDATE function.
This code example requires that you create the following text constants in the C/AL Globals window.
Text constant
ENU value
Text000
‘The reference date is: %1 \’
Text001
‘The expression: %2 returns %3\’
Text002
‘The expression: %4 returns %5\’
Text003
‘The expression: %6 returns %7’
Copy Code
Expr1 := ‘<CQ+1M-10D>’; // Current quarter + 1 month – 10 days
Expr2 := ‘<-WD2>’; // The last weekday no.2, (last Tuesday)
Expr3 := ‘<CM+30D>’; // Current month + 30 days
RefDate := 052196D;
Date1 := CALCDATE(Expr1, RefDate);
Date2 := CALCDATE(Expr2, RefDate);
Date3 := CALCDATE(Expr3, RefDate);
MESSAGE(Text000 + Text001 + Text002 + Text003,
RefDate, Expr1, Date1, Expr2, Date2, Expr3, Date3);
The message window displays the following text:
The reference date is: 05/21/96
The expression: CQ+1M-10D returns 07/20/96
The expression: -WD2 returns 05/14/96
The expression: CM+30D returns 06/30/96


“——————————————————————————————————————————————————

Appoġġ traduzzjoni: http://amzn.to/1Z7d5oc
——————————————————————————————————————————————————
Microsoft Dynamics NAV – Kif To: Sib Start Data u Tmiem Data tal Xahar Preċedenti

Lokali / Varjabbli Globali:

Isem datatype Sottotip Tul
StartDate Data
EndDate Data

StartDate = data tal-aħħar xahar Bidu.
EndDate = L-aħħar jum tax aħħar xahar.
StartDate: = CALCDATE ( “”<- CM-1M>””); // StartDate = 2012/01/08
EndDate: = CALCDATE ( “”CM””, StartDate); // EndDate = 31/08/2012.
CALCDATE

Minn Microsoft Dynamics NAV 2009 R2 Għajnuna.
Jikkalkula data ġdida li hija bbażata fuq l-espressjoni data u data ta ‘referenza.
NewDate: = CALCDATE (DateExpression [, Data])
parametri
DateExpression
Tip: Test, Kodiċi, jew DateFormula
L-espressjoni data jista ‘jkun kwalunkwe tul. -Sekwenza huwa interpretat mix-xellug għal-lemin bl subexpression wieħed kull darba. Ir-regoli li ġejjin jiddeskrivu l-sintassi validu ta ‘espressjonijiet data:
· DateExpression = [<SubExpression>] [<SubExpression>] [<SubExpression>]
· <SubExpression> = [<Sign>] <Terminu>
· <Sign> = + | –
· <Terminu> = <Numru> <Unità> | <Unità> <Numru> | <Prefiss> <Unità>
· <Numru> = numru sħiħ pożittiv
· <Taqsima> = D | WD | W | M | Q | Y (D = jum, WD = weekday, W = il-ġimgħa, M = il xahar, Q = kwart, Y = sena)
· <Prefiss> = C (Ċ = attwali)
Dawn ir-regoli ta ‘produzzjoni turi li l-espressjonijiet data tikkonsisti minn żero, wieħed, tnejn, jew tlieta subexpressions. Kull subexpression jinkludi sinjal obbligatorju u terminu. Dawn li ġejjin huma xi eżempji tipiċi ta ‘termini:
· 30d (30 jum; jikkorrispondi għal <Numru> <Unità>)
· WD2 (weekday numru 2; jikkorrispondi għal <Unità> <Numru>)
· CW (ġimgħa kurrenti; jikkorrispondi għal <Prefiss> <Unità>)
Il-kalendarju intern ta ‘C / SIDE jibda nhar it-Tnejn u jispiċċa l-Ħadd. Dan ifisser li it-tnejn hija weekday 1 u l-Ħadd huwa weekday 7.
Żball run-time iseħħ jekk l-sintassi ta DateExpression hija żbaljata.
data
Tip: Data
Uża dan il-parametru mhux obbligatorju li jiddefinixxu data ta ‘referenza. In-nuqqas hija d-data tas-sistema attwali.
Jekk inti jħalli barra dan il-valur mhux obbligatorja d-data tas-sistema attwali qed tintuża.