0

AGE function

Not so long ago I watched a video lesson where they talked about the global function ageYM. but I can't find where to copy this formula. can anyone tell me where all the global functions can be downloaded or viewed?

Thanks for advanse 

9 replies

null
    • John_Halls
    • 3 yrs ago
    • Reported - view

    Hi

     

    If you tell me what ageYM does I am sure I can re-create it for you.

     

    Regards John

    • iliper LTD
    • iliper_LTD
    • 3 yrs ago
    • Reported - view

    Hello John 
      We specify the date of birth, and the system shows how many years and months of months.

     https://www.youtube.com/watch?v=TKedij51ruQ&t=1132s from this video

    • John_Halls
    • 3 yrs ago
    • Reported - view

    Hi

     

    You need to put your global function in the Global script definitions section, found under the Options tab

     

    Screenshot 2021-06-25 at 13.29.33

     

    The script from the video is this (screenshot taken from the video)

     

    Screenshot 2021-06-25 at 13.28.12

     

    Here is that code typed so you can copy and paste it into your solution

     

    function ageYM(date : date) do
    let xDate := date;
    let extraYr := 0;
    let extraMo := 0;
    let xMo := 12 - month(xDate) + month(today());
    if xMo >= 0 then
    if xMo < 12 then
    extraYr := 0;
    extraMo := xMo
    else
    if xMo = 12 then
    extraYr := 1;
    extraMo := 0
    else
    if xMo > 12 then
    extraYr := 0;
    extraMo := xMo - 12
    end
    end
    end
    else
    extraYr := 0;
    extraMo := 12 - month(xDate) + month(today()) - month(xDate)
    end;
    age(date) + extraYr + " Years " + extraMo + " Months"
    end

     

    Regards John

    • John_Halls
    • 3 yrs ago
    • Reported - view

    I have double checked the code as written and I am sure I have copied it out correctly but I have been testing it and I am getting some odd behaviour. I wouldn't use this code just yet!

    • iliper LTD
    • iliper_LTD
    • 3 yrs ago
    • Reported - view

    I also have, that's why I wrote here, I thought I was making a mistake.
    Thank you for your attention and help

    • John_Halls
    • 3 yrs ago
    • Reported - view

    That code was fundamentally flawed plus it doesn't take into account the day of the month. Here is my code

     

    function ageYM(date : date) do
    let xDate := date;
    let fullYears := year(today()) - year(xDate) - 1;
    let monthsBefore := 12 - month(xDate);
    let monthsAfter := month(today()) - number(day(today()) < day(xDate));
    let allMonths := monthsBefore + fullYears * 12 + monthsAfter;
    let years := floor(allMonths / 12);
    let months := allMonths % 12;
    years + " Years " + months + " Months"
    end

    You can see from this table it working (and the original not working)

     

    Screenshot 2021-06-25 at 16.42.50

     

    Regards John

    • John_Halls
    • 3 yrs ago
    • Reported - view

    It's less readable but this can be shortened to

     

    function ageYM(date : date) do
    let months := (year(today()) - year(date) - 1) * 12 + 12 - month(date) + month(today()) - number(day(today()) < day(date));
    floor(months / 12) + " Years " + months % 12 + " Months"
    end

     

    Regards John

    • John_Halls
    • 3 yrs ago
    • Reported - view

    Did this work for you?

    • iliper LTD
    • iliper_LTD
    • 3 yrs ago
    • Reported - view

    Hello John

     

    function ageYM(date : date) do
    let xDate := date;
    let fullYears := year(today()) - year(xDate) - 1;
    let monthsBefore := 12 - month(xDate);
    let monthsAfter := month(today()) - number(day(today()) < day(xDate));
    let allMonths := monthsBefore + fullYears * 12 + monthsAfter;
    let years := floor(allMonths / 12);
    let months := allMonths % 12;
    years + " Years " + months + " Months"
    end

Content aside

  • Status Answered
  • 3 yrs agoLast active
  • 9Replies
  • 449Views