Skip to main content

Notifications

Community site session details

Community site session details

Session Id : gIjN2Ki4Js+iIaR1BIKxc4
Power Apps - Building Power Apps
Answered

DateDiff in months with decimal digits

Like (0) ShareShare
ReportReport
Posted on 16 Feb 2021 10:53:03 by 3,458 Super User 2024 Season 1

Hi all,

 

I am trying to find a way to calculate a DateDiff in months but with 2 Decimal digits.

 

So for example the DateDiff output for "01.01.2013" and "06.03.2013" (Format "dd.mm.yyyy") should be 2,2

 

Thanks in advance for your help

Categories:
  • i-technology Profile Picture
    2 on 17 Nov 2021 at 15:58:28
    Re: DateDiff in months with decimal digits

    Was struggling with this, and finally settled for 

    var nbrMonths = YEARFRAC(startDate, endDate) * 12
    var result = DIVIDE(something, nbrMonths, 0)

     

    Was much easier than i thought 🙂 

  • daisaacs Profile Picture
    4 on 09 Sep 2021 at 11:22:23
    Re: DateDiff in months with decimal digits

    So I implemented this exactly as is into my app, and the only issue I'm seeing as that when I add the initials dates in for Both Start and End Date, the DateDiff outputs the correct value.

    When When Testing - I update the End date again (by 1 day), and can see the output change correctly (IE: bother the number value and decimal values updated correctly).

    However if i do the exact same thing for the Start Date, the number value, changes correctly, but the decimal always stays the same for some reason

    Examples

    1. Initial Values Set (Where Term in Months is the Date Difference)

    daisaacs_0-1631186288839.png


    2. When I update the Expire Date - the value for Term in Months updates

    daisaacs_1-1631186341700.png


    3. If I revert back - it updates again correctly

    daisaacs_2-1631186385842.png


    4. However no when i update the start Date - only the integer portion of the 'Term in Months' updates NOT the decimal portion ()decimal always remains the same

    Example 1

    daisaacs_3-1631186436128.png

    Example 2

     

    daisaacs_4-1631186451767.png

     









  • PowerRanger Profile Picture
    3,458 Super User 2024 Season 1 on 16 Feb 2021 at 13:51:08
    Re: DateDiff in months with decimal digits

    And to get the DateDiff out of the Collection I use: 

     
    Sum(MyDateTable2,MonthCounter)
  • Verified answer
    PowerRanger Profile Picture
    3,458 Super User 2024 Season 1 on 16 Feb 2021 at 13:49:38
    Re: DateDiff in months with decimal digits

    Hi now came up with this solution:

     

    Set(
     varMonthsDiff,
     DateDiff(
     dtpStartDate.SelectedDate,
     dtpEndDate.SelectedDate,
     Months
     )
    );
    Clear(MyDateTable);
    ForAll(
     Sequence(varMonthsDiff + 1),
     Collect(
     MyDateTable,
     {
     CurrentSequenz: CountRows(MyDateTable),
     StartDate: dtpStartDate.SelectedDate,
     EndDate: dtpEndDate.SelectedDate,
     FirstDayOfMonth: Date(
     Year(
     DateAdd(
     dtpStartDate.SelectedDate,
     CountRows(MyDateTable),
     Months
     )
     ),
     Month(
     DateAdd(
     dtpStartDate.SelectedDate,
     CountRows(MyDateTable),
     Months
     )
     ),
     1
     ),
     LastDayOfMonth: Date(
     Year(
     DateAdd(
     dtpStartDate.SelectedDate,
     CountRows(MyDateTable),
     Months
     )
     ),
     Month(
     DateAdd(
     dtpStartDate.SelectedDate,
     CountRows(MyDateTable),
     Months
     )
     ) + 1,
     0
     )
     }
     )
    );
    ClearCollect(
     MyDateTable2,
     AddColumns(
     MyDateTable,
     "DaysInMonth",
     DateDiff(
     FirstDayOfMonth,
     LastDayOfMonth
     ) + 1,
     "MonthCounter",If(EndDate > LastDayOfMonth,1,RoundUp((1/(DateDiff(
     FirstDayOfMonth,
     LastDayOfMonth
     ) + 1))*(DateDiff(FirstDayOfMonth,EndDate,Days)+1),2))
     )
    )

     

     

    Might not be the cleanest solution biut seems to be working.

  • PowerRanger Profile Picture
    3,458 Super User 2024 Season 1 on 16 Feb 2021 at 12:21:14
    Re: DateDiff in months with decimal digits

    Well, this is required for a calculation where we do need the exact difference in months.
    So what I would do manually:

    "01.01.2013" and "06.03.2013"

    1. 01.012013 - 31.01.2013 = 1 month

    2. 01.02.2013 - 28.02.2013 = 1 month

    3. 01.03.2013 - 06.03.2013 = 6 days = (1/31)*6 = 0,1935...

    ==> 2,1935 months ==> 2,2 Months

     

  • Community Power Platform Member Profile Picture
    on 16 Feb 2021 at 11:31:08
    Re: DateDiff in months with decimal digits

    Hi,

     

    What is the logic behind the second 2? As to me the DateDiff in months is just 2?

    I mean you could do string manipulation such as:

    HenryARPhillips_0-1613475048047.png

     



    But I presume the above is not what you are after?

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,518 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,751 Most Valuable Professional

Leaderboard