cancel
Showing results for
Did you mean:
Anonymous
Not applicable

## Need to calculate hours

Hello, i am making an app that count the extra hours worked. I am using four dropdowns, startHour, EndHour, startMin,Endmin

Set(_Hora;[0;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20;21;22;23]);;
Set(_Minutos;[00;01;02;03;04;05;06;07;08;09;10;11;12;13;14;15;16;17;18;19;20;21;22;23;24;25;26;27;28;29;30;31;32;33;34;35;36;37;38;39;40;41;42;43;44;45;46;47;48;49;50;51;52;53;54;55;56;57;58;59]);;

Do u know how i can work with this numbers, how to calculate hours?

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

Hi @Anonymous,

You can get the time values of those dropdowns by using the Time() function. To calculate the difference in minutes between both the start and end dropdowns, you could use (adjust if I wrote the dropdown names incorrectly):

``````DateDiff(
Time(
startHour.Selected.Value;
startMin.Selected.Value;
0
);
Time(
EndHour.Selected.Value;
EndMin.Selected.Value;
0
);
TimeUnit.Minutes
)``````

If you want to show the difference in and Hour:Minute template (e.g. on a label) you could use:

``````With(
{
minutes: DateDiff(
Time(
startHour.Selected.Value;
startMin.Selected.Value;
0
);
Time(
EndHour.Selected.Value;
EndMin.Selected.Value;
0
);
TimeUnit.Minutes
)
};
Text(
Time(
Int(minutes / 60);
Mod(
minutes;
60
);
0
);
DateTimeFormat.ShortTime24
)
)``````

As an additional trick: you don't have to write out all of the numbers manually to set your variables. You could use the sequence function and define how many numbers you would like. Let's take _Minutos as an example:

``Set(_Minutos; Sequence(59))``

If this solves your question, would you be so kind as to accept it as a solution.

Thanks!

Super User

Hi @Anonymous,

You can get the time values of those dropdowns by using the Time() function. To calculate the difference in minutes between both the start and end dropdowns, you could use (adjust if I wrote the dropdown names incorrectly):

``````DateDiff(
Time(
startHour.Selected.Value;
startMin.Selected.Value;
0
);
Time(
EndHour.Selected.Value;
EndMin.Selected.Value;
0
);
TimeUnit.Minutes
)``````

If you want to show the difference in and Hour:Minute template (e.g. on a label) you could use:

``````With(
{
minutes: DateDiff(
Time(
startHour.Selected.Value;
startMin.Selected.Value;
0
);
Time(
EndHour.Selected.Value;
EndMin.Selected.Value;
0
);
TimeUnit.Minutes
)
};
Text(
Time(
Int(minutes / 60);
Mod(
minutes;
60
);
0
);
DateTimeFormat.ShortTime24
)
)``````

As an additional trick: you don't have to write out all of the numbers manually to set your variables. You could use the sequence function and define how many numbers you would like. Let's take _Minutos as an example:

``Set(_Minutos; Sequence(59))``

If this solves your question, would you be so kind as to accept it as a solution.

Thanks!

Announcements

#### Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.

#### Copilot Cookbook Challenge | WINNERS ANNOUNCED | Win Tickets to the Power Platform Conference

We are excited to announce the "The Copilot Cookbook Community Challenge random winners have been selected for the Challenge.  Thank you to everyone who participated in this challenge.    Copilot Cookbook Gallery:Power Apps Cookbook Gallery: 1. @swaminawale  1. @renatoromao     2.  @SpongYe  2.   @nickpotts10  *Please note if for any reason a winner declines, we will have another random drawing.   Check out all of the Cookbook Submissions: 1. Copilot Studio Cookbook Gallery: https://aka.ms/CS_Copilot_Cookbook_Challenge 2. Power Apps Copilot Cookbook Gallery: https://aka.ms/PA_Copilot_Cookbook_Challenge   There will be 5 chances to qualify for the final drawing: Early Bird Entries: March 1 - June 2Week 1: June 3 - June 9Week 2: June 10 - June 16Week 3: June 17 - June 23Week 4: June 24 - June 30WINNERS ANNOUNCED - JULY 8th     At the end of each week, we will draw 5 random names from every user who has posted a qualifying Copilot Studio template, sample or demo in the Copilot Studio Cookbook or a qualifying Power Apps Copilot sample or demo in the Power Apps Copilot Cookbook. Users who are not drawn in a given week will be added to the pool for the next week. Users can qualify more than once, but no more than once per week. Four winners will be drawn at random from the total qualifying entrants. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once. If they are drawn multiple times, another user will be drawn at random. Prizes:  One Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 (\$1800 value, does not include travel, lodging, or any other expenses) Winners are also eligible to do a 10-minute presentation of their demo or solution in a community solutions showcase at the event. To qualify for the drawing, templates, samples or demos must be related to Copilot Studio or a Copilot feature of Power Apps, Power Automate, or Power Pages, and must demonstrate or solve a complete unique and useful business or technical problem. Power Automate and Power Pagers posts should be added to the Power Apps Cookbook. Final determination of qualifying entries is at the sole discretion of Microsoft. Weekly updates and the Final random winners will be posted in the News & Announcements section in the communities on July 29th, 2024. Did you submit entries early?  Early Bird Entries March 1 - June 2:  If you posted something in the "early bird" time frame complete this form: https://aka.ms/Copilot_Challenge_EarlyBirds if you would like to be entered in the challenge. Early Bird Submissions: @renato Week 1 Results:  Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Copilot Cookbook Gallery:Power Apps Cookbook Gallery:1.  @Mathieu_Paris 1.   @SpongYe 2.  n/a2.   @Deenuji 3.  n/a3.   @Nived_Nambiar  4.  n/a4.   @ManishSolanki 5.  n/a5.    n/a   Week 2 Results:  Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Copilot Cookbook Gallery:Power Apps Cookbook Gallery:1. Kasun_Pathirana1. ManishSolanki2. cloudatica2. madlad3. n/a3. SpongYe4. n/a4. n/a5. n/a5. n/a     Week 3 Results:  Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Copilot Cookbook Gallery:Power Apps Cookbook Gallery:1. Parul_Yadav_Neo1. n/a2. SpongYe2. n/a3. n/a3. n/a4. n/a4. n/a5. n/a5. n/a   Week 4 Results:  Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Copilot Cookbook Gallery:Power Apps Cookbook Gallery:1. @nickpotts10  1. @ShrushtiShah  2. @Suniti_0020 2. @swaminawale 3. n/a3. @farukhis786 4. n/a4. @ManishSolanki  5. n/a5.  n/a