Forum Discussion

22 Replies

  • I think somehow I lost part of the formula when I pasted it in.

    AGE and decimal months

    // replace the [DOB] field with your date of birth field

    var date DOB = [DOB];

    var number Years =

    Year(Today())-Year($DOB)
    -
    If(
    Month(Today()) 0, $MonthsDifference, 12 + $MonthsDifference);

    var number Age = Round($Years + $Months/12,0.1)

    If($Age >= 0, $Age)
  • Sorry, I think that something weird was happening when I was copying and pasting from my iPad.  I am back on my regular computer now.

    //AGE and decimal months

    // replace the [DOB] field with your date of birth field

    var date DOB = [DOB];

    var  number  Years = 

    Year(Today())-Year($DOB)
    -
    If(
    Month(Today())<Month($DOB)
    or
    (Month(Today())=Month($DOB) and Day(Today())<Day($DOB)),1,0);

    var number MonthsDifference = Month(Today()) - Month($DOB) ;
    var number Months = If($MonthsDifference > 0, $MonthsDifference, 12 + $MonthsDifference);

    Round($Years + $Months/12,0.1)
    • JustinParker's avatar
      JustinParker
      Qrew Trainee
      Hello,

      I am using this formula field to calculate years with the company in my QB App and Im getting the following bug.

      The bug occurs when the employee start month/day is after the same month/day for that month.  It fixes itself after the month changes.  Here are 2 examples.

      1. Employee Joe Smith is hired on March 3rd 2018.  His "years with company" field will display 1.0 until April 1st when it will revert to 0.1
      2. Employee Jane Doe will be with the company for 1 year on March 20th 2018. On March 20th her "years with the company" will display 1.0.  On March 21st her "years with the company field" will switch to 2.0 until April 1st well it will revert to 1.1

      Any help would be great!
    • JustinParker's avatar
      JustinParker
      Qrew Trainee
      Here you go!
      //
      var date DOB = [Date of Hire];



      var  number  Years = 


      Year(Today())-Year($DOB)
      -
      If(
      Month(Today())<Month($DOB)
      or
      (Month(Today())=Month($DOB) and Day(Today())<Day($DOB)),1,0);


      var number MonthsDifference = Month(Today()) - Month($DOB) ;
      var number Months = If($MonthsDifference > 0, $MonthsDifference, 12 + $MonthsDifference);


      Round($Years + $Months/12,0.1)
      //