Dateformula

Madhan
Member Posts: 96
Great Day All,
How to convert a dateformula field to text or code.
For eg:
1. I am having a dateformula field of value 12M. I want the output as
12 Months.
2. If the value of the dateformula field is 12D. I want the output as
12 Days.
3. If the value of the dateformula field is 12Y. I want the output as
12 Years.
can any one help me.
How to convert a dateformula field to text or code.
For eg:
1. I am having a dateformula field of value 12M. I want the output as
12 Months.
2. If the value of the dateformula field is 12D. I want the output as
12 Days.
3. If the value of the dateformula field is 12Y. I want the output as
12 Years.
can any one help me.
0
Comments
-
As far as I know, there's no possibility to do that in the run-time - I'm afraid you'll have to write your own parsing/formatting logic. Please take into account that the date formula's you use in your examples are relatively simple: more complex formula's could potentially be quite difficult to describe in normal language.
Good luck!Kind regards,
Jan Hoek
Product Developer
Mprise Products B.V.0 -
You can use FORMAT to put them in a string so it is easier to parse them, but remember that the characters can be different in different languages.
Something a lot of people seem to forget (even the Navision W1-developers).Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
Hi kriki,
Using format function i have converted my dateformula field to string. Then, after that how to proceed further to reach my output what i want?
can you guide me....0 -
Thanx for you clue. I got the solutions......Thax a lot0
-
A few examples of possible dateformulas (in english):
-12D = minus 12 days
+4M = plus 4 months
30D = 30 days
2W = 2 weeks
CM+10D = Current month plus 10 days
CM+1M = Current month plus one month
CQ+1M+20D=Current quarter plus one month plus 20 days
CW+1W = Current week plus one week
D15 = On the 15th of each month
M12 = on the 12th month
So we have to do a lot. I will not write all code (I'll also use some pseudocode).
And I didn't test anything, but at least you will have a good starttxtString := FORMAT(TheDateFormula); txtResult := ''; WHILE txtString <> '' DO BEGIN txtToken := GetToken(); CASE txtToken OF 'CM': txtResult := txtResult + ' ' + 'Current Month'; 'CQ': txtResult := txtResult + ' ' + 'Current Quarter'; ... '+': txtResult := txtResult + ' ' + 'plus'; '-': txtResult := txtResult + ' ' + 'minus'; 'D': txtResult := txtResult + ' ' + 'day(s)'; 'M': txtResult := txtResult + ' ' + 'month(s)'; ELSE BEGIN // remaining are 1,12,123,D1,D15,M12 IF COPYSTR(txtToken,1,1) IN ['0'..'9'] THEN txtResult := txtResult + ' ' + txtToken ELSE BEGIN // remaining are D1,D15,M12 IF COPYSTR(txtToken,1,1) = 'D' THEN txtResult := txtResult + ' ' + STRSUBSTNO('On the %1th of each month',COPYSTR(txtToken,2)); ELSE IF COPYSTR(txtToken,1,1) = 'D' THEN txtResult := txtResult + ' ' + STRSUBSTNO('on the %1th month',COPYSTR(txtToken,2)); ELSE ERROR('Unknown Token:%1',txtToken); END; END; END; END;
Function "GetToken":
This function gets a substring and returns it.
The substring can exist of 1 or more chars. The chars must belong together.
Tokens can be:
CM,CQ,CW,-,+,1,12,123,D,M,Y,Q,D15,D1,M12
When you have the token, the chars must be removed from txtString.
Some code:IF COPYSTR(txtString,1,2) IN ['CM','CQ','CW'] THEN BEGIN OtxtReturnValue := COPYSTR(txtString,1,2); txtString := COPYSTR(txtString,3); EXIT; END; IF COPYSTR(txtString,1) IN ['+','-'] THEN BEGIN OtxtReturnValue := COPYSTR(txtString,1,1); txtString := COPYSTR(txtString,2); EXIT; END; IF COPYSTR(txtString,1) IN ['0'..'9'] THEN BEGIN OtxtReturnValue := take the complete string of numbers txtString := COPYSTR(txtString,...); EXIT; END; IF COPYSTR(txtString,1) IN ['D','M','Y','Q'] THEN BEGIN txtHelp := COPYSTR(txtString,1,1); txtString := COPYSTR(txtString,2); IF NOT(COPYSTR(txtString,1) IN ['0'..'9']) THEN BEGIN // I only have D,M,... OtxtReturnValue := txtHelp; END ELSE BEGIN // I have something like D15 or M12 or D1 txtHelp2 := GetToken(); // We're going recursive here and have something like 15,12,1 as return-value OtxtReturnValue := txtHelp + txtHelp2; // so our returnvalue will be D15 or M12 or D1 END; EXIT; END ERROR('Unable to intpret the following string:%1',txtString);
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions