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