Frustration With Power Apps Dates

The manipulation of dates in Power Apps can be a source of irritation for both developers and business users alike. Developers often grapple with the complexities of date handling when working with databases or SharePoint lists, while business users might find themselves at a loss for words – and not the polite kind. If you’ve ever struggled with this, rest assured, you are in good company. the challenge isn’t unique to Power Apps; it’s a common headache across software dealing with dates. Here we will focus on easing one particular pain point: choosing between AM/PM vs. military time.

Automation for Power Apps Dates Uses Military Time

When an Edit form is created by the standard method of selecting from the add menu, date and time fields are bound to surprise. The date field is divided into three fields, not one (See Image 1). This is how Power Apps dates are applied to a form automatically.

  • First Field – Date Picker – Allows interaction with a calendar to choose the correct day, month, and year.
  • Second Field – Dropdown Box – Allows selection of the desired hour, using military time. (The hours span 00 – 23 by military standards.)
  • Third Field – Dropdown Box – Allows the selection of the desired minute ranging from 00 – 59.
Image 1

Setting Up Power Apps Dates Using AM/PM

To utilize AM/PM vs military time, you will need to skip over the easy, automated way of the Edit form from the Insert menu. The following portion of this post will show you how to build a form manually and submit it to a SharePoint list connection creating a new item. To simplify this example, we will only have two columns within the list, “Title” and “Date_of_Doom”. Please look at Image 2 to follow along with the explanation.

Image 2

Set up for Power Apps Dates Form

To achieve simplification for Power Apps Dates, two functions are going to be used. Patch to create the new item manually and DateTime to put the date and time collected in the appropriate formatting. The form in Image 2 contains two text labels, one text input box, one date picker, three drop down, and a button. Place the controls as shown in image above giving each a noteworthy name. (For Example: dpdHours for the drop down for hours.)

Configuration of the Submit Button

Below in the Code Snippet is the full configuration string needed to make this work. I will break down the controls in a list format to bring understanding to what control is being referenced.

  • txtTitle = text input box for free text for the title
  • calTestDate = date picker for selecting a date
  • dpdAMPM = drop down box for selecting AM or PM
  • dpdHours = drop down box for selecting hour
  • dpdMinutes = drop down box for selecting minutes
Patch(Testing_Dates, Defaults(Testing_Dates),{Title:txtTitle.Text,Date_Of_Doom:DateTime(Year(calTestDate.SelectedDate),Month(calTestDate.SelectedDate),Day(calTestDate.SelectedDate),If(dpdAMPM.SelectedText.Value = "PM",Hour(dpdHours.SelectedText.Value+12),Hour(dpdHours.SelectedText.Value)),dpdMinutes.SelectedText.Value, 0)})

The secret sauce that makes this work is the If statement identifying if dpdAMPM is AM or PM. If PM is selected, for the time to be correct, 12 hours must be added to make turn it to military time. Behind the scenes, a date is nothing but a floating number. There are 24 hours in a day. For the number to portray the correct date and time, military time is necessary.

Conclusion

Power Apps Dates use military time due to the way dates and times are managed in the background of computers in general. Though most countries use military (24 hour) time, some use AM and PM to discern what part of the day you are in. To simplify working with dates and times for some of your application users, you will need to increase the difficulty level in how you deal with them yourself. Following the steps provided is a way to do this.