cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
BrandonMcG
Level: Powered On

Get AM or PM from DateTime

Is there a way to get the AM or PM from an entity DateTime field? 

 

I can get Date() Hour() Minute() separated ... but can't figure out how to get the AM/PM designation from the entity field. 

 

Other than something like this?

 

Right(DateTimeValue,2)

 

4 REPLIES 4
Microsoft dinusc
Microsoft

Re: Get AM or PM from DateTime

Since you can get the Hour() value, would something like If(Hour() >11,"PM,"AM") work for you? Example:

If(Hour(Now())>11,"PM","AM")
Community Support Team
Community Support Team

Re: Get AM or PM from DateTime

Hi @BrandonMcG,

 

Are you using CDS as data source? If so, by default in the Display Form, the DateTime field is already shown as AM/PM format:
Capture.PNG

 

You could create an auto-generated app to have a test. 

 

If you mean that you want the AM/PM shows in Edit Form, you can edit the card (after unlocking it) and add an AM/PM option. Here are some properties that you'll need to updat. The new dropdown is called AM/PM "AmPmValue1":

AmPmValue1.Items: ["AM", "PM"]
AmPmValue1.Default: If(Hour(Parent.Default) < 12, "AM", "PM")
HourValue1.Items: ["12","01","02","03","04","05","06","07","08","09","10","11"]
HourValue1.Default: Text(If(Mod(Hour(Parent.Default), 12) = 0, 12, Mod(Hour(Parent.Default), 12)),"00")
DataCard1.Update: DateValue1.SelectedDate + Time(If(AmPmValue1.Selected.Value = "PM", 12, 0) + Mod(Value(HourValue1.Selected.Value), 12), Value(MinuteValue1.Selected.Value), 0)

 

 

See detailed solution here:

https://powerusers.microsoft.com/t5/General-Discussion/DatePicker-AM-PM/td-p/42766

 

Regards,

Mona 

Community Support Team _ Mona Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
BrandonMcG
Level: Powered On

Re: Get AM or PM from DateTime

Thank you!

 

I'm using the CDS, but with a custom input to enter date/time so I had to go a different route, but I was able to set the Default based on the time.

 

AMPMDropdown.Default = Right(Text(editIncidentTime),2)

powerapps-incident-ampm.png

 

 

 

 

Highlighted
mehul_sompura
Level: Powered On

Re: Get AM or PM from DateTime

I


@v-monli-msft wrote:

Hi @BrandonMcG,

 

Are you using CDS as data source? If so, by default in the Display Form, the DateTime field is already shown as AM/PM format:
Capture.PNG

 

You could create an auto-generated app to have a test. 

 

If you mean that you want the AM/PM shows in Edit Form, you can edit the card (after unlocking it) and add an AM/PM option. Here are some properties that you'll need to updat. The new dropdown is called AM/PM "AmPmValue1":

AmPmValue1.Items: ["AM", "PM"]
AmPmValue1.Default: If(Hour(Parent.Default) < 12, "AM", "PM")
HourValue1.Items: ["12","01","02","03","04","05","06","07","08","09","10","11"]
HourValue1.Default: Text(If(Mod(Hour(Parent.Default), 12) = 0, 12, Mod(Hour(Parent.Default), 12)),"00")
DataCard1.Update: DateValue1.SelectedDate + Time(If(AmPmValue1.Selected.Value = "PM", 12, 0) + Mod(Value(HourValue1.Selected.Value), 12), Value(MinuteValue1.Selected.Value), 0)

 

 

See detailed solution here:

https://powerusers.microsoft.com/t5/General-Discussion/DatePicker-AM-PM/td-p/42766

 

Regards,

Mona 


 


@v-monli-msft wrote:

Hi @BrandonMcG,

 

Are you using CDS as data source? If so, by default in the Display Form, the DateTime field is already shown as AM/PM format:
Capture.PNG

 

You could create an auto-generated app to have a test. 

 

If you mean that you want the AM/PM shows in Edit Form, you can edit the card (after unlocking it) and add an AM/PM option. Here are some properties that you'll need to updat. The new dropdown is called AM/PM "AmPmValue1":

AmPmValue1.Items: ["AM", "PM"]
AmPmValue1.Default: If(Hour(Parent.Default) < 12, "AM", "PM")
HourValue1.Items: ["12","01","02","03","04","05","06","07","08","09","10","11"]
HourValue1.Default: Text(If(Mod(Hour(Parent.Default), 12) = 0, 12, Mod(Hour(Parent.Default), 12)),"00")
DataCard1.Update: DateValue1.SelectedDate + Time(If(AmPmValue1.Selected.Value = "PM", 12, 0) + Mod(Value(HourValue1.Selected.Value), 12), Value(MinuteValue1.Selected.Value), 0)

 

 

See detailed solution here:

https://powerusers.microsoft.com/t5/General-Discussion/DatePicker-AM-PM/td-p/42766

 

Regards,

Mona 



@v-monli-msft wrote:

Hi @BrandonMcG,

 

Are you using CDS as data source? If so, by default in the Display Form, the DateTime field is already shown as AM/PM format:
Capture.PNG

 

You could create an auto-generated app to have a test. 

 

If you mean that you want the AM/PM shows in Edit Form, you can edit the card (after unlocking it) and add an AM/PM option. Here are some properties that you'll need to updat. The new dropdown is called AM/PM "AmPmValue1":

AmPmValue1.Items: ["AM", "PM"]
AmPmValue1.Default: If(Hour(Parent.Default) < 12, "AM", "PM")
HourValue1.Items: ["12","01","02","03","04","05","06","07","08","09","10","11"]
HourValue1.Default: Text(If(Mod(Hour(Parent.Default), 12) = 0, 12, Mod(Hour(Parent.Default), 12)),"00")
DataCard1.Update: DateValue1.SelectedDate + Time(If(AmPmValue1.Selected.Value = "PM", 12, 0) + Mod(Value(HourValue1.Selected.Value), 12), Value(MinuteValue1.Selected.Value), 0)

 

 

See detailed solution here:

https://powerusers.microsoft.com/t5/General-Discussion/DatePicker-AM-PM/td-p/42766

 

Regards,

Mona 




In this way, when we input 12 pm it turns the am pm value to Am.

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (4,813)