6 Replies Latest reply on Sep 14, 2009 2:11 AM by marzuki

    Script for Birthday

    RickSr

      Title

      Script for Birthday

      Post

      How can I build a script to automatically calculate a persons age by using the System Date/Time function and a Birthday field that will automatically put the answer in a field called age.

      I would like to see the answer in years and Months or just years would do as well.

       

      I don't want to have a field called current date that I have to manually input the current date into.

       

      I would think that this type of script would be very useful to a lot of users.

       

      Thank you for any assistance.

        • 1. Re: Script for Birthday
          Orlando
            

          Hi RickSr

           

          Here is a calculation I use for working out someone's age, just create a calculated field and change the references to Birthday   

           

             

            Year ( Get ( CurrentDate ) ) - 

            Year ( Birthday ) - Case ( Get ( CurrentDate ) < 

            Date ( Month ( Birthday ) ; Day ( Birthday ) ; Year ( Get ( CurrentDate ) ) ) ; 1 ; 0 ) 

           

          Also under storage options set it to Do not store calculated result.

           

          This uses the Get ( CurrentDate ) function so there is no need for any additional field with the current date. 

           

          I hope this helps. 

           

          • 2. Re: Script for Birthday
            nan01
              

            The following will give you age in years:

             

            You take the integer portion of the difference between the current date and the birthday divided by the average number of days per year.

             

            Int((GetCurrentDate)-Birthday)/365.25)

            • 3. Re: Script for Birthday
              RickSr
                

              Thank you both for such a quick reply.

              I will give them both a try.

              I feel that this type should be a canned script, I'm sure that it would get

              a lot of use.

               

              Thanks again

               

              Rick

              • 4. Re: Script for Birthday
                RickSr
                  

                Thank you......

                Your fix worked just fine.

                 

                Rick

                • 5. Re: Script for Birthday
                  synergy46
                    

                  I found and have used this:

                   

                  //calculates age in years
                  // input:date
                  //output: integer
                  Let([
                  currentYear=Year(Get(CurrentDate));
                  birthyear=Year(DOB);
                  birthdayThisYear=Date(Month(DOB);Day(DOB);currentYear)
                  ];
                  currentYear-birthyear-Case(Get(CurrentDate)<birthdayThisYear;1;0)
                  )




                  • 6. Re: Script for Birthday
                    marzuki
                      

                    I am glad to have found this page when I was looking for a script for birthday. Only as I read through the replies did I realise the "Get" function in FM10 pro. With that in hand, I wish to share my script which I hope would be useful to others as well.

                     

                    Round ( (Get ( CurrentDate ) - Birthday) / 365 ; 0 ) 

                     

                    Thank you.

                     

                     

                    M Marzuki