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 Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (1,728)