web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Copilot Studio / PVA Need a calculation...
Copilot Studio
Unanswered

PVA Need a calculation of years and months between two dates

(0) ShareShare
ReportReport
Posted on by

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)

 

I have the same question (0)
  • Pstork1 Profile Picture
    68,678 Most Valuable Professional 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

  • wherdzik Profile Picture
    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
    68,678 Most Valuable Professional 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
    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
  • Verified answer
    Pstork1 Profile Picture
    68,678 Most Valuable Professional 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')

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Copilot Studio

#1
Romain The Low-Code Bearded Bear Profile Picture

Romain The Low-Code... 265 Super User 2025 Season 2

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 257 Super User 2025 Season 2

#3
Sam_Fawzi Profile Picture

Sam_Fawzi 84 Super User 2025 Season 2

Last 30 days Overall leaderboard