How to get last day of a year?

Yabu13Yabu13 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:
Text := '01.05.15';
PostingDate := '31.12.' + COPYSTR(Text,7,2);
EXIT(PostingDate);

There must be a better solution?

Answers

  • Jan_VeenendaalJan_Veenendaal Member Posts: 206
    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 Veenendaal
  • DenSterDenSter Member Posts: 8,307
    First - welcome to Mibuso Yabu13 :smile:

    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.
  • Yabu13Yabu13 Member Posts: 12
    The suggestion of Jan_Veenendaal does not work.
  • Jan_VeenendaalJan_Veenendaal Member Posts: 206
    edited 2016-07-19
    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.


    utnmsd9wpawn.jpg
    Jan Veenendaal
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    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 logic
  • Yabu13Yabu13 Member Posts: 12
    Thank you very much. GETRANGEMAX does function very well.
Sign In or Register to comment.