Date time fields in Power Apps are displayed, by default, in a 24 hour format. I was working on a project a few days ago where the customer wanted the time displayed in 12 hour format both while creating a new record and updating/viewing an existing record.
A date time field, by default, looks like this:
To convert this to a 12 hour format, follow the following steps:
- Unlock the date time data card
- Add a new dropdown to be used for AM/PM to the date time field's data card
- Set the Items property of this dropdown to
["AM", "PM"]
- Set the Default property of this dropdown to
If(Hour(Parent.Default) <12, "[$-en-US]AM", "PM")
- Change the Items property of the Hour dropdown to
["00","01","02","03","04","05","06","07","08","09","10","11","12"]
- Change the Default property of this dropdown to
Text(If(Mod(Hour(Parent.Default),12) = 0, 12, Mod(Hour(Parent.Default), 12)), "[$-en-US]00")
- Change the Update property of the data card to
DateValue1.SelectedDate + Time(If(AMPMValue1.Selected.Value = "PM", 12, 0) + Mod(Value(HourValue1.Selected.Value), 12), Value(MinuteValue1.Selected.Value), 0)
With these changes, the form looks like this (I added another data card to compare the time in 24 hour format with the 12 hour format):
I then updated the time from 8 PM to 9 PM:
To summarize, the above steps not only help in displaying a date time field of an existing record in 12 hour format, but it also let's you update the date time field for an existing record and also at the time of creating a new record.
Have fun! Get addicted!
Looks great and is easy to implement! Thank you!
Thank you so much for your comment! Am glad you liked the post!