Hi,
i am looking for a solution to get simply the last day of a year, especially, if the date is in a text data type like "01.05.15..12.12.16" or only "01.05.15".
I have the following solution with a simple function:
Text := '01.05.15';
PostingDate := '31.12.' + COPYSTR(Text,7,2);
EXIT(PostingDate);
There must be a better solution?
Answers
1. Make a variable of type 'Date' - in the code I will use the name 'Date'
2. Write in your function:
https://rockwithnav.wordpress.com/2016/04/14/handle-datetime-use-dotnet-variable/
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/
To elaborate on Jan's answer - he's recommending you to use standard C/AL date formulas. Search around the online help for more syntax for CALCDATE and also for FORMAT, which is necessary to understand the standard formats, and also on how to create your own formats.
The < and > signs are used to take out the language specific string format. By putting those around the date formula, it will work in any language. The C in 'CY' stands for 'current'. The default value is '+C' which gives you the last of the period in the formula. You can do this for year (CY), for month (CM) and week (CW). You can also get the FIRST of the period by using the minus sign. For instance, '<-CM>' will get you the first of the month.
RIS Plus, LLC
Please check if your text is formatted according to NAV date-formatting.
You could add an 'ELSE' clause to my code to handle things when the Text cannot be evaluated to a Date type.
"01.05.15..12.12.16"
then please use GETRANGEMIN or GETRANGEMAX first to get one of those dates and then apply above logic
-Mohana
http://mohana-dynamicsnav.blogspot.in/
https://www.facebook.com/MohanaDynamicsNav