cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
BrandonMcG Resolver I
Resolver I

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
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
Community Support

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 Resolver I
Resolver I

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

 

 

 

 

mehul_sompura Helper I
Helper I

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
MBAS Gallery 2020

MBAS Gallery 2020

Watch Microsoft Business Applications Summit sessions on-demand.

firstImage

New Ranks and Rank Icons released on April 21!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power Apps Community!

Top Solution Authors
Top Kudoed Authors
Users online (6,854)