Skip to main content

Notifications

Calling Actions from Copilot Studio
Answered

PVA Need a calculation of years and months between two dates

Posted on by 58

Hi Community, trying to figure out how to get years and months between two dates. I am using an entity to grab start date and end date.  Then I want to create a flow that subtracts the dates to get me years and months.  So I expect the bot to output a text string that says "The calculated years of experience is 10 years and 3 month(s). 

 

PVA BOT questions:

wherdzik_2-1696773107253.png

 

My attempt at creating the flow:

 

 

wherdzik_0-1696772977732.pngwherdzik_1-1696772997584.png

 

This is what my compose action has but I know its not correct:

 

div(sub(ticks(variables('EndDate')), ticks(variables('StartDate'))),864000000000)

 

  • Verified answer
    Pstork1 Profile Picture
    Pstork1 1,997 on at
    Re: PVA Need a calculation of years and months between two dates

    You can nest div() functions as necessary.

    formatNumber(div(div(outputs('DaysDifference'),365.0),3),'###.00')
  • wherdzik Profile Picture
    wherdzik 58 on at
    Re: PVA Need a calculation of years and months between two dates

    @Pstork1 Thank you that works great.  Sorry Pstork1 to keep on doing this but one more question.

     

    I also need to take this function and divided by 3.  Basically we have a different way of calculating years for different positions.  Some positions get the full credit but some positions if they have a certain experience we give them a partial credit which is divided by 3. Or a 3 for 1 credit.  When I try to just add / 3 at the end the expression faults.  How can I divide this by 3. 

     

    formatNumber(div(outputs('DaysDifference'),365.0),'###.00') / 3
  • Pstork1 Profile Picture
    Pstork1 1,997 on at
    Re: PVA Need a calculation of years and months between two dates

    Todo that just change the years function to the following.

     

    formatNumber(div(outputs('Compose'),365.0),'###.00')

     

    Having one of the numbers in the div() as a float will return a float results.

  • wherdzik Profile Picture
    wherdzik 58 on at
    Re: PVA Need a calculation of years and months between two dates

    @Pstork1 .  Thank you.  If I want to change my approach and change to just decimal places.  So forget the months but just like 9.57 for example.  

  • Pstork1 Profile Picture
    Pstork1 1,997 on at
    Re: PVA Need a calculation of years and months between two dates

    Because of the differing length of months its always going to be an approximation, but this setup works.

    1) Calculate the number of Days between using DateDifference()

    2) Calculate the number of years by dividing the result by 365 days/year

    3) Calculate the number of months by using MOD() to get the remainder from #2 and divide by an average of 30 days/month.

    image.png

Helpful resources

Quick Links

Exciting News for Copilot Studio Communi…

Get ready to experience a whole new level of engagement with the Copilot Studio…

Celebrating the May Super User of the…

LaurensM is an exceptional contributor to the Power Platform Community…

Check out the Copilot Studio Cookbook…

We are excited to announce our new Copilot Cookbook Gallery in the Community…

Leaderboard

#1
renatoromao Profile Picture

renatoromao 6,459

#2
Pstork1 Profile Picture

Pstork1 1,997

#3
Expiscornovus Profile Picture

Expiscornovus 1,708

Leaderboard

Featured topics