Forum Discussion

ReneeHansen1's avatar
ReneeHansen1
Qrew Cadet
6 months ago

Create a formula duration over 5 years

Hello, I am trying to figure this out How to calculate a duration for each year based on a varying start date? The start date can be at any month of the year (just calculating months, not days) a...
  • ReneeHansen1's avatar
    ReneeHansen1
    6 months ago

    Thank you! I ended up joining a Quickbase Office Hours with Sam, and we discussed this option:

    1st year:

    var date SD=[Start Date];
    var date ED=LastDayOfYear([Start Date]);
     
    (Year($ED)-Year($SD))/12 // start off with 12 months
     
    +If(Month($ED)>=Month($SD),0) //add 12 months if the last year was fully completed

    + If((Month($ED)>=Month($SD)),Month($ED)-Month($SD),12+Month($ED)-Month($SD)) // add the number of months between the month numbers.
     
    //-If(Day($ED)<Day($SD),0,0) // but if the day did not catch up to the start date's day number, then subtract 1.

    2nd Year:

    var number secondyear=[Months Needed]-[First Year Duration];

    If($secondyear>12,12,$secondyear)

    and then repeat the pattern for 3, 4, 5 years.  Then My calculation fields are working independently of any variables mashed into one field.  

    *(Posted to help anyone else!)

    Thanks!!