Calculating Employment Duration

Calculating Employment Duration

Hi All,

I struggled to find a solution that would calculate an employment duration based on a user selected date and Publish the result to a field as follows : 2 Years 4 Months 5 Days as an example.

Here is the solution i could come up with and works (I hope this helps for anyone reading this):

  1.     CurrentDayEmployment = input.Employment_Start_Date.getDay(); // Gets the selected employment Days of the year I.E 01-02-2017 would produce 1
        CurrentYearEmployement = input.Employment_Start_Date.getYear(); // gets the selected employment year I.E 01-02-2017 would produce 2017
        CurrentMonthEmployment = input.Employment_Start_Date.getMonth(); // gets the selected employment month I.E 01-02-2017 would produce 2
        YearCalcEmployment = (days360(input.Employment_Start_Date,today) / 365.25).tolong(); // Calculates the years between the employment date and current date taking into account leap years
        CurrentDay = zoho.currentdate.getDay(); // saves the current day
        CurrentMonth= zoho.currentdate.getMonth(); // saves the current month
        CurrentYear= zoho.currentdate.getYear(); // saves the current year
        MonthCalc1 = (CurrentMonth - CurrentMonthEmployment); // Current Month Value - Selected Employment Month Value
        MonthCalc2 = (CurrentMonthEmployment - CurrentMonth); // Selected Employment Month Value -  Current Month Value
        DayCalc1 = (CurrentDay - CurrentDayEmployment); // Current Day - Selected Employment Day
        DayCalc2 = (CurrentDayEmployment - CurrentDay); // Selected Employment Day - Current Day

    if (DayCalc1 > 0)
    {
            input.Total_Employment = YearCalcEmployment + " Years , " + MonthCalc1 + " Months , " + DayCalc1 + " Days "; // Total_Employment is a single line Field
    }
    Else If (DayCalc2 > 0)
    {
        input.Total_Employment = YearCalcEmployment + " Years , " + (MonthCalc2*-1)  + " Months , " + DayCalc2 + " Days ";
    }