5 Replies Latest reply on May 25, 2015 11:28 AM by rebfree

    Chronological Age as of Certain Date

    cjsweatt

      Hi Everyone!

       

      I am in need of a chronological age field which counts as of December 1 of the current year.  I am using the following code to get the age:

      FullAge (calculation, text result) =

      GetAsText ( Year ( Get ( CurrentDate ) )  - Year ( Date of Birth ) - If ( Get ( CurrentDate ) <  Date ( Month ( Date of Birth ) ; Day ( Date of Birth ) ; Year ( Get ( CurrentDate ) ) ) ; 1 ; 0 ) ) & " Years, " & GetAsText ( Mod ( Month ( Get ( CurrentDate ) ) - Month ( Date of Birth ) + 12 - If ( Day ( Get ( CurrentDate ) ) < Day ( Date of Birth ) ; 1 ; 0 ) ; 12 ) ) & " Months, " & GetAsText ( Day ( Get ( CurrentDate ) ) - Day ( Date of Birth )  + If ( Day ( Get ( CurrentDate ) )  ≥ Day ( Date of Birth ); 0 ; If ( Day ( Get ( CurrentDate ) - Day ( Get ( CurrentDate ) ) ) < Day ( Date of Birth ) ; Day ( Date of Birth ) ; Day ( Get ( CurrentDate ) - Day ( Get ( CurrentDate ) ) ) ) ) ) & " Days "

      What else do I need to add in order to have it count as of December 1 of the current year?

       

      Any help is always appreciated!

       

      Thank you!

        • 1. Re: Chronological Age as of Certain Date
          Mike_Mitchell

          Hello, cjsweatt.

           

          You're going to a lot of extra trouble to get the age. Try this (courtesy of Winfried Huslik, FileMaker Custom Function:age ( date1 ; date2 ):

           

          -----------------------------------------------------------

           

          Let ( [

              neg = Case ( date1 > date2 ; -1 ; 1 ) ;

              d1 = Case ( neg < 0 ; date2 ; date1 ) ;

              d2 = Case ( neg < 0 ; date1 ; date2 ) ;

           

              d = mod ( Day ( d2 ) - Day ( d1 ) ; Day (

                Date ( Month ( d1 ) + 1 ; 0; year ( d1 ) ) ) ) ;

           

              m = mod ( Month ( d2 ) - Month ( d1 ) -

                ( Day ( d2 ) < Day ( d1 ) ) ; 12 ) ;

           

              y = Year ( d2 ) - Year ( d1 ) - ( ( Month ( d2 ) -

                ( Day ( d2 ) < Day ( d1 ) ) ) < Month ( d1 ) )

            ];

              y * neg & ¶ &

              m * neg & ¶ & 

              d * neg & ¶ &

              y & " years, " & m & " months, and " & d & " days" & ¶

          )

           

          -------------------------------------------------------------

           

          Just pass it whatever two dates you need as date1 and date2. Since this is written as a custom function, it assumes you will pass them in as parameters to the function. If you're using it as a regular calculation, you can just define them at the top of the Let statement, like this:

           

          Let ( [

              date1 = Get ( CurrentDate ) ;

              date2 = Date of Birth ;

              neg = Case ( date1 > date2 ; -1 ; 1 ) ;

              d1 = Case ( neg < 0 ; date2 ; date1 ) ;

          ...

           

          If you need it to give you the age as of December 1 of the current year, just use:

           

               Date ( 12 ; 1 ; Year ( Get ( CurrentDate )))

           

          instead of

           

               Get ( CurrentDate )

           

          HTH

           

          Mike

          • 2. Re: Chronological Age as of Certain Date
            cjsweatt

            @Mike_Mitchell: WOW!  That is great information!  I feel slightly embarrassed 1; that I just now saw you replied a few days ago... My apologies! I'm not getting e-mail notifications for some reason. And 2; I'm still so new to this that the code is a bit over my head.

             

            If you don't mind talking me through this just a bit more so that I can learn a bit of what's going on here.  I have the following fields:

                 "Date of Birth" as a Date type

                 "Chrono Age" calculation type

             

            With the example you gave, I have to create two additional fields: date1, and date2, and make them both Date types.  I input the calculation in the Chrono Age field, which is set to a Calculation type.

             

            Again, I apologize if I'm way off on this..I'm a bit overwhelmed.

             

            I did download the sample database from the link you provided - and it seems like there's a lot going on.

             

            Thank you again for your help!!

            • 3. Re: Chronological Age as of Certain Date
              cjsweatt

              NEVERMIND!  Geeze... I just caught on to custom functions.  Woah! I feel pretty foolish...  I was going all around the world to accomplish this.  Ignore my first reply.  It took me a few times talking myself through this before I realized that "Custom Functions" and "Creating my own" was a thing in filemaker.

               

              This brings me to another question.  The results in the box come out as, for example "14102114 years, 10 months & 21 days"

               

              How can I rewrite this to only show "14 years, 10 months & 21 days"?  I want to eliminate the first eight characters.  I saw that in the example database, they added extra text boxes for "years" "months" and "days", and resized the function output box to show only the numbers in a vertical format.  I would like this as a linear output, so I deleted the paragraph symbols, but now I'm left with the long string of numbers, and then the result I want six characters in.

              • 4. Re: Chronological Age as of Certain Date
                Mike_Mitchell

                If I had to guess, I suspect one of the dates you're passing in isn't cast as a date. Try using the GetAsDate ( ) function to make sure it's being treated as a date (rather than as text).

                 

                If that doesn't work, post either a copy of your file or a copy of your exact calculation and we'll try to troubleshoot.

                • 5. Re: Chronological Age as of Certain Date
                  rebfree

                  Thank you, Mike_Mitchell!!!!!!

                  I'm using this to calculate dates till a rent increase - looked all over for a clear answer, and here was yours. 

                  Thanks for taking the time to post it!

                   

                  Rebecah