Skip to main content

Notifications

Copilot Studio - Calling Actions from Copilot S...
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)

 

  • Verified answer
    Pstork1 Profile Picture
    Pstork1 64,996 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 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 64,996 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 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 64,996 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

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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,666

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,996

Leaderboard

Featured topics