3 Replies Latest reply on Mar 7, 2012 5:22 AM by DarioVasquez

    How to calculate birthdate with Years, Months, Day and Hours?

    DarioVasquez

      Actually I need this for making an database for neonatology. I have the fields called birthdate and birthhour. Actually I have the script to get the age in Y M D.

       

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

      Thanks in Advance

        • 2. Re: How to calculate birthdate with Years, Months, Day and Hours?
          DavidJondreau

          My summary of that thread is that defining a date range in terms of months requires compromise. This is an aspect of our definition of month and nothing to do with Filemaker.

           

          What's the point of tracking how old a child is down to the hour, if a two month old baby born at he beginning of December is 3 days older than a two month old baby born at the beginning of February? That question may be above your pay grade, but you should keep it in mind when tracking age in months.

           

          Try this which incorporates your existing calc but gives you hours:

           

          Let([

          now = Get ( CurrentTime ) ;

          hours = ( ( now - birthHour ) / 60 / 60 ) ;

          hours1 = Floor ( Mod ( hours ; 24 ) ) ;

           

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

           

          result = ymd & " " & hours

          ];

          result

          )

          1 of 1 people found this helpful
          • 3. Re: How to calculate birthdate with Years, Months, Day and Hours?
            DarioVasquez

            I have modified your script and worked great. Im putting the code, bold shows the mods.

             

            GetAsText ( Year ( Get ( CurrentDate ) )  - Year ( Birthdate ) - If ( Get ( CurrentDate ) <  Date ( Month ( Birthdate ) ; Day ( Birthdate ) ; Year ( Get ( CurrentDate ) ) ) ; 1 ; 0 ) ) & " Years, " & GetAsText ( Mod ( Month ( Get ( CurrentDate ) ) - Month ( Birthdate ) + 12 - If ( Day ( Get ( CurrentDate ) ) < Day ( Birthdate ) ; 1 ; 0 ) ; 12 ) ) & " Meses, " & GetAsText ( Day ( Get ( CurrentDate ) ) - Day ( Birthdate )  + If ( Day ( Get ( CurrentDate ) )  ≥ Day ( Birthdate ); 0 ; If ( Day ( Get ( CurrentDate ) - Day ( Get ( CurrentDate ) ) ) < Day ( Birthdate ) ; Day ( Birthdate ) ; Day ( Get ( CurrentDate ) - Day ( Get ( CurrentDate ) ) ) ) ) ) & " Days, " & Hour ( GetAsTime ( Get ( CurrentTime ) - Birthhour )) & " Hours"

             

            Thanks for the inspiration