cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

How to get hour & minutes from string and bind to date picker control

Team,

I am having text field in SharePoint list. In that the datetieme value is saved as string. For Ex. 7/22/2019 06:05.

I want to bind this value in date pciker control in power apps form.

 

I tried the below approach but it is not working properly if the time is less than 12 hours.

If(EditFormShiftDetails.Mode=FormMode.New,Hour(Now()),Text(Hour(DateTimeValue(DateText)),"[$-en-US]00"))

DateText is the internal field in SharePoint list. Please help me.

 

Thanks

Philip

1 ACCEPTED SOLUTION

Accepted Solutions
Anonymous
Not applicable

Hi Shilendra,

I just swap the if condition and it started working.

 

If(EditFormShiftDetails.Mode=FormMode.Edit, Text(Minute(DateTimeValue(DateText)),"[$-en-US]00"), Minute(Now()))

With Split function

 

If(EditFormShiftDetails.Mode=FormMode.Edit,Last(Split(Last(Split(DateText, " ")).Result, ":")).Result, Minute(Now()))

Thanks for your support.

 

Thanks

Philip

View solution in original post

18 REPLIES 18
Anonymous
Not applicable

HI @Anonymous 

 

To get the time from datetime value you can do the following:

 

Text(DateTimeValue(DateText), "[$-en-US]hh:mm")

 

for all formats you can refer to - https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-text

 

 

Thanks.

Anonymous
Not applicable

Hi Shilendra,

It is not working. It is displayed as 00 in hour drop down.

If(EditFormShiftDetails.Mode=FormMode.New,Hour(Now()),Text(DateTimeValue(DateText),"[$-en-US]hh:mm"))

Thanks

Philip

Anonymous
Not applicable

Hi @Anonymous 

 

what is the value in DateText

 

 Thanks.

Anonymous
Not applicable

Hi Shilendra,

 

The value of DateText field is 7/23/2019 06:05

StarttimeText.png

Anonymous
Not applicable

Hi Shilendra,

 

If the hour value is greater than or equal to 12 hours, then the below option formula is working.

Text(DateTimeValue(DateText),"[$-en-US]hh")

If the hour is less than 12, then it is displayed as 00.

Any idea? Please help me.

 

Thanks

Philip

Anonymous
Not applicable

Hi Shilendra,

I am having the field like below and it is hidden from the screen. The internal name of the field is DateText. If I used the below formula, I am getting the syntax error as "This rule creates a circular reference between properties, which is not allowed. A property cannot reference itself or other properties affected by its value.".

 

DateText_DataCard.png

 

If(EditFormShiftDetails.Mode=FormMode.New,Hour(Now()),Text(Hour(DateTimeValue(StartTimeTextInput.Text)), "[$-en-US]hh"))

Any idea? Please help.

 

Thanks,

Philip

Anonymous
Not applicable

Hi @Anonymous 

 

To which control are you assigning the below formula. Looks like both DateText and StartTimeInput refer to the same datacard and you are setting the below formual to StartTiimeInput control and so circular reference.

 

Thanks.

Anonymous
Not applicable

Hi Shilendra,

I am trying to setup the formula in different data card, not in the StartTimeInputText datacard.

 

I am able to get the hour value in text box or label. But it is not setting to drop down.

 

Thanks

Philip

Anonymous
Not applicable

Hi Shilendra,

If I used the below formula, it is setting the correct value.

Text(Hour(DateTimeValue(DateText)), "[$-en-US]00")

If I set the below formula based on the form mode, then it is displayed as 00 for the hour less than 12.

If(EditFormShiftDetails.Mode=FormMode.New,Hour(Now()),Text(Hour(DateTimeValue(DateText)),"[$-en-US]00"))

Any idea or suggestion please?

 

Thanks

Philip

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (1,209)