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

Announcements

News and Announcements icon
Community site session details

Community site session details

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

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)

 

  • Pstork1 Profile Picture
    69,665 Most Valuable Professional on at

    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

    @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
    69,665 Most Valuable Professional on at

    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

    @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
    69,665 Most Valuable Professional on at

    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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Copilot Studio

#1
Mohsin Ali Profile Picture

Mohsin Ali 106

#2
11manish Profile Picture

11manish 102 Super User 2026 Season 2

#3
Sapan Patel Profile Picture

Sapan Patel 54

Last 30 days Overall leaderboard