How to get last day of a year?

Yabu13
Member Posts: 12
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:
There must be a better solution?
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?
0
Answers
-
This will function if your Text contains just a date (not a date-range):
1. Make a variable of type 'Date' - in the code I will use the name 'Date'
2. Write in your function:IF EVALUATE(Date,Text) THEN EXIT(FORMAT(CALCDATE('<CY>',Date)));
Jan Veenendaal1 -
Check out this link and the way if it helps you.
https://rockwithnav.wordpress.com/2016/04/14/handle-datetime-use-dotnet-variable/Thanks
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/0 -
First - welcome to Mibuso Yabu13
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.1 -
The suggestion of Jan_Veenendaal does not work.0
-
Could you provide details of what you have tried, and what does not work? ( I have a working function here , see attachment)
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.
Jan Veenendaal0 -
if you are using above login on dates like
"01.05.15..12.12.16"
then please use GETRANGEMIN or GETRANGEMAX first to get one of those dates and then apply above logic1 -
Thank you very much. GETRANGEMAX does function very well.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