Skip to main content

How to Get the Hour and Minute of a Time in Power Apps

· 4 min read
Jagdish Kumawat
Founder @ Dewiride

Hour and Minute take a time apart. For 22:30 they return 22 and 30, as numbers. Hour always counts on the 24-hour clock, from 0 to 23, whatever format the time is shown in.

The example is the Overtime Timesheet app, which reads the hour and minute of the times people choose and puts them onto the day the shift started.

Syntax​

Syntax
Hour(DateTime)
Minute(DateTime)

From Microsoft's Day, Month, Year, Hour, Minute, Second, and Weekday functions page:

FunctionReturns
Hour0 (12:00 AM) to 23 (11:00 PM)
Minute0 to 59
Second0 to 59

They take any date/time value, including a Time on its own.

Step 1: Get the Hour​

I put the formula into a text control's Text for a moment, so Studio's preview strip shows the result:

Any text control → Text
Hour(Time(22, 30, 0))

The formula bar with Hour(Time(22, 30, 0)), the preview strip reading 22 with Data type number, and the text control showing 22

Step 2: Get the Minute​

Any text control → Text
Minute(Time(22, 30, 0))

The formula bar with Minute(Time(22, 30, 0)), the preview strip reading 30 with Data type number, and the text control showing 30

What They're For​

In the example, people choose a time from a combo box (How to Let Users Pick a Time in Power Apps), and the app puts that time onto the date of the shift. Hour and Minute supply the time's parts to DateTime:

From the app's ShiftStart function
DateTime(Year(ShiftDate), Month(ShiftDate), Day(ShiftDate), Hour(StartAt), Minute(StartAt), 0)

StartAt is the chosen time, cmbStartLO.Selected.Value. How to Combine a Date and a Time in Power Apps with DateTime explains why this works on the nights the clocks change.

Common Mistakes​

MistakeWhat happensDo this instead
Expecting Hour to return 10 for 10 PMIt returns 22Use it as a 24-hour number
Showing a time by joining Hour and Minute9:5 instead of 09:05Text(t, "hh:mm")
Reading the combo box's record instead of its timeHour(cmbStartLO.Selected) isn't a timeHour(cmbStartLO.Selected.Value)

Troubleshooting​

SymptomLikely causeFix
The hour is 0 for a time no one choseThe time is blankCheck IsBlank before using it
Minutes look roundedThe time list only has whole minutes, such as every fiveThat's the list, not Minute

FAQ​

How do I get the minutes since midnight?​

Multiply the hours by 60 and add the minutes: Hour(t) * 60 + Minute(t).

Is there a function for seconds?​

Yes, Second, from 0 to 59.

Conclusion​

Hour(t) and Minute(t) return a time's parts as numbers, the hour on the 24-hour clock. Use them to place a time on a date or to count minutes; use Text to show a time.

Additional Resources​