cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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)

 

5 REPLIES 5
Highlighted
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")
Highlighted
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.
Highlighted
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

 

 

 

 

Highlighted
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.

Highlighted
Responsive Resident
Responsive Resident

Re: Get AM or PM from DateTime

this works for me:

 

 

Spoiler
DateValue1.DefaultDate: Parent.Default

DateValue1.Format: DateTimeFormat.ShortDate

AmPmValue1.Items: ["AM", "PM"]

AmPmValue1.Default: If(Hour(Parent.Default) < 12, "AM", "PM")

HourValue1.Items: ["12","1","2","3","4","5","6","7","8","9","10","11"]

HourValue1.Default:
    If(
        Hour(Parent.Default) = 0, 12,
        Hour(Parent.Default) < 13, Hour(Parent.Default),
        Hour(Parent.Default) < 24, Hour(Parent.Default) - 12
    )

MinuteValue1.Items: ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59"]

MinuteValue1.Default: If(Minute(Parent.Default)<10, "0" & Minute(Parent.Default), Minute(Parent.Default))

DataCard1.Update:
    DateValue1.SelectedDate +
    Time(
        If(
            AmPmValue1.Selected.Value = "AM" && Value(HourValue1.Selected.Value) = 12,     00,
            AmPmValue1.Selected.Value = "AM" && Value(HourValue1.Selected.Value) <> 12,   Value(HourValue1.Selected.Value),
            AmPmValue1.Selected.Value = "PM" && Value(HourValue1.Selected.Value) = 12,      12,
            AmPmValue1.Selected.Value = "PM" && Value(HourValue1.Selected.Value) <> 12,    Value(HourValue1.Selected.Value) + 12
        ),
        Value(MinuteValue1.Selected.Value),
        00
)

 

 

Helpful resources

Announcements
secondImage

New Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

August 2020 CYST Challenge

Check out the winners of the recent 'Can You Solve These?' community challenge!

Experience what’s next for Power Apps

Join us for an in-depth look at the new Power Apps features and capabilities at the free Microsoft Business Applications Launch Event.

Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Users online (5,392)