cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
DataGuy85
New Member

Date Calculation and Print to PDF

Good Afternoon Community,

 

I have a challenge. I am doing a employment experience calculator. Testing my abilities in PowerApps. In the calculator I am trying to calculate the years, months and days difference for multiple period. Now figuring out the DateDiff in years, months and days is between the start and end days is easy. I did that but here is the scenerio.

 

Lets say I have a total of 1700 days. That is 4 years, 7 months and 21 days which I am able to replicate in excel using the DatedIf function.  In PowerApps, I want that same result in txtTotalTimeElapsed which is highlighted below. I have tried taking the value of each periods DateDiff(input1,input2,Days) then divide it by 365 to get the years and by 30 days to get the months but the calculations are not adding up. I feel like a concat function would be the solution but I was wrong. Any help would be appreciated. 

 

ScreenShot.JPG

Side question, I am not using a form but I would like the user to be able to print the data as a PDF in a specific format.

 

1 ACCEPTED SOLUTION

Accepted Solutions
v-qiaqi-msft
Community Support
Community Support

Hi @DataGuy85,

Try as below:

With(
    {
        totalDays: DateDiff(
            DatePicker2.SelectedDate,//statrt date
            DatePicker3.SelectedDate,//end date
            Days
        ) + 1
    },
    With(
        {
            totalYears: RoundDown(
                totalDays / 365,
                0
            ),
            remainingDaysFromYearsRollUp: Mod(
                totalDays,
                365
            )
        },
        With(
            {
                MonthsInRemainingDays: RoundDown(
                    remainingDaysFromYearsRollUp / 30,
                    0
                ),
                remainingDaysFromMonthsRollUp: Mod(
                    remainingDaysFromYearsRollUp,
                    30
                )
            },
            totalYears & " years / " & MonthsInRemainingDays & " months / " & remainingDaysFromMonthsRollUp & " days"
        )
    )
)

vqiaqimsft_0-1651728874750.png

 

Best Regards,
Qi

View solution in original post

2 REPLIES 2
v-qiaqi-msft
Community Support
Community Support

Hi @DataGuy85,

Try as below:

With(
    {
        totalDays: DateDiff(
            DatePicker2.SelectedDate,//statrt date
            DatePicker3.SelectedDate,//end date
            Days
        ) + 1
    },
    With(
        {
            totalYears: RoundDown(
                totalDays / 365,
                0
            ),
            remainingDaysFromYearsRollUp: Mod(
                totalDays,
                365
            )
        },
        With(
            {
                MonthsInRemainingDays: RoundDown(
                    remainingDaysFromYearsRollUp / 30,
                    0
                ),
                remainingDaysFromMonthsRollUp: Mod(
                    remainingDaysFromYearsRollUp,
                    30
                )
            },
            totalYears & " years / " & MonthsInRemainingDays & " months / " & remainingDaysFromMonthsRollUp & " days"
        )
    )
)

vqiaqimsft_0-1651728874750.png

 

Best Regards,
Qi
DataGuy85
New Member

Thank you that fixed it.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Users online (5,814)