Calculate Birthday - Age and Days

TFCrowther
Member Posts: 35
Enter in your birthday into a form field name "Birth Date" and it will return
Agrstr = Your age.
Age1 = Days since your last birthday.
Toby Crowther
Agrstr = Your age.
Age1 = Days since your last birthday.
“Birth Date” - OnValidate IF "Birth Date" <>0D THEN BEGIN Age:= TODAY -"Birth Date" ; //Returns number of days old Age2:=(Age/365.2364); //Returns number of years old as Decimal - Takes into Account Leap Years i:= STRPOS(FORMAT(Age2),'.'); IF i>0 THEN Agestr:= COPYSTR(FORMAT(Age2),1,i-1) //Return no of years old as string – removes decimal value ELSE Agestr:= FORMAT(Age2); //Return no of years old as string LastBDayTxt := '+' + AgeStr + 'Y'; //Creates a date formula ie +30Y LastBDayDate := CALCDATE(LastBDayTxt,"Birth Date"); //Returns last Birthday Age1:= (TODAY - LastBDay); //Returns number of Days since last birthday END;
Toby Crowther
0
Comments
-
hi,
I've a problem with this formula:
TODAY: 4.09.2018 (september)
Birth: 3.09.2008 => age: 10 ok!
Birth: 4.09.2008 => age: 9 (9.999...) not ok, it's birthday!
Birth 5.09.2008 => age: 9 ok!
any idea? something with the 365.2364?
BR
Chris#### Only one can survive ######0 -
I'd take a bit different approach:
CheckAgeAndBirthday(BirthdayDate : Date;CheckAgeDate : Date;VAR AgeYears : Integer;VAR AgeDays : Integer;VAR IsBirthDayDate : Boolean) AgeYears := 0; REPEAT AgeYears +=1; TestDate := CALCDATE( STRSUBSTNO('<+%1Y>', AgeYears), BirthdayDate); UNTIL TestDate >= CheckAgeDate; AgeYears -= 1; AgeDays := CheckAgeDate - BirthdayDate; IsBirthDayDate := TestDate = CheckAgeDate; //for test only: MESSAGE('Birthday: %1, Check Date: %2, AgeYears: %3, AgeDays:%4, Is Birthday: %5', BirthdayDate, CheckAgeDate, AgeYears, AgeDays, IsBirthDayDate);
Check dates:CheckAgeAndBirthday(030908D, 040918D, AgeYears, AgeDays, IsBirthDayDate); CheckAgeAndBirthday(040908D, 040918D, AgeYears, AgeDays, IsBirthDayDate); CheckAgeAndBirthday(050908D, 040918D, AgeYears, AgeDays, IsBirthDayDate);
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-031 -
Slawek_Guzek wrote: »I'd take a bit different approach:
CheckAgeAndBirthday(BirthdayDate : Date;CheckAgeDate : Date;VAR AgeYears : Integer;VAR AgeDays : Integer;VAR IsBirthDayDate : Boolean) AgeYears := 0; REPEAT AgeYears +=1; TestDate := CALCDATE( STRSUBSTNO('<+%1Y>', AgeYears), BirthdayDate); UNTIL TestDate >= CheckAgeDate; AgeYears -= 1; AgeDays := CheckAgeDate - BirthdayDate; IsBirthDayDate := TestDate = CheckAgeDate; //for test only: MESSAGE('Birthday: %1, Check Date: %2, AgeYears: %3, AgeDays:%4, Is Birthday: %5', BirthdayDate, CheckAgeDate, AgeYears, AgeDays, IsBirthDayDate);
Check dates:CheckAgeAndBirthday(030908D, 040918D, AgeYears, AgeDays, IsBirthDayDate); CheckAgeAndBirthday(040908D, 040918D, AgeYears, AgeDays, IsBirthDayDate); CheckAgeAndBirthday(050908D, 040918D, AgeYears, AgeDays, IsBirthDayDate);
Hi @Slawek_Guzek,
Will it work in the below case?
CheckAgeAndBirthday(210991D, 210992D, AgeYears, AgeDays, IsBirthDayDate);
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