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
-
Hi
If you tell me what ageYM does I am sure I can re-create it for you.
Regards John
-
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
-
Hi
You need to put your global function in the Global script definitions section, found under the Options tab
The script from the video is this (screenshot taken from the video)
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"
endRegards John
-
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!
-
I also have, that's why I wrote here, I thought I was making a mistake.
Thank you for your attention and help -
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"
endYou can see from this table it working (and the original not working)
Regards John
-
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"
endRegards John
-
Did this work for you?
-
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