cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
audrieg
Level 10

Date Expression - Text Label vs. Text Input?

I have used the same function for a text label and a text input control. But the returned values are different. I have two questions:

 

1. Why are the formats different if the expression is the same? (The only difference with the top one is that it has a prefix of
"Date/Time: " & ) - I literally copied the expression from the top text box to the bottom one, and only deleted the prefix.
See screen shot below to understand what I mean by variance :
--Label has regular time,
--Input Box has military time, and
--Label has AM PM and Input Box doesn't

2. Is there anything special I need to do in order to submit the input value (bottom one shown in image) to a date column in SharePoint (right now it doesn't seem to be working)?

 

Notes:

--We are using these dates to log items from paper (so we can't use created and modified times on SharePoint)

--I'm not using the Power App templates, I'm patching the data down to SharePoint. i.e. Patch() function.

 

Thank you in advance for your help.

 

Time Variance.PNG

1 ACCEPTED SOLUTION

Accepted Solutions
PowerApps Staff AndyPennell
PowerApps Staff

Re: Date Expression - Text Label vs. Text Input?

The Label one needs to do the concatenation outside the Text function:

"Date/Time: " & Text(Now(), "mm/dd/yy hh:mm:ss am/pm")

 

Now() is not a string: it returns a date. Whenn you add it to the string it converts it and loses its "date-ness".

7 REPLIES 7
PowerApps Staff AndyPennell
PowerApps Staff

Re: Date Expression - Text Label vs. Text Input?

If you always want 12-hour time in US format, use a formula of Text(Now(),"mm/dd/yyyy hh:mm:ss am/pm")

 

I cannot explain why one is different to the other though, I get 24-hour time by default for both on my machine.

 

(Sorry I dont know anything about submitting dates to SP).

PowerApps Staff rgruian
PowerApps Staff

Re: Date Expression - Text Label vs. Text Input?

 

Can you please list here the exact expressions for your two controls? I can see one of them, the other one is unclear to me.

 

One thing to note is that date/time values in PowerApps are not text/strings. They are numeric, and flow through the dataflow graph from / into controls as such. At the point where they need to be presented in text form, they are projected to strings. This typically happens in one of three main ways:

 

1. Explicit projection using the Text function. The format is specified in the formula. E.g. label.Text = Text(dt, "mm/dd/yyyy hh:mm a/p")

2. Implicit projection via type coercion from date/time to text. The format is fixed and culture-specific. For en-US, it's typically "mm/dd/yyyy hh:mm:ss a/p". For example: label.Text = Now()

3. Implicit projection by a control that manipulates date/time values. An example would be a calendar control.

 

I am trying to understand what your formulas are, so I can see which of these cases actually kick in (in your case).

 

 

Regarding your second question, I suspect the date/time value for SharePoint needs to be properly typed. You should be able to use the DateTimeValue or DateValue functions (as appropriate) to convert text, for example from a TextInput control, to a date/time value compatible with SharePoint.

Radu Gruian [MSFT] ** PowerApps Staff
audrieg
Level 10

Re: Date Expression - Text Label vs. Text Input?

Here are the two expressions my apologies for being unclear. These expressions plus the screen shot should further clarify:

 

In the label:

Text( "Date/Time: " & Now(), "mm/dd/yyyy hh:mm:ss" )

 

In the Text Input Box (Default value that the consumer of the form can edit):

Text(Now(), "mm/dd/yyyy hh:mm:ss" )

 

 

 

PowerApps Staff AndyPennell
PowerApps Staff

Re: Date Expression - Text Label vs. Text Input?

The Label one needs to do the concatenation outside the Text function:

"Date/Time: " & Text(Now(), "mm/dd/yy hh:mm:ss am/pm")

 

Now() is not a string: it returns a date. Whenn you add it to the string it converts it and loses its "date-ness".

audrieg
Level 10

Re: Date Expression - Text Label vs. Text Input?

LOL - that's funny because that is the one that was working as I expected! Let me try that and see if I now have two problems.

 

Thank you - will post back here as soon as I give it a try.

PowerApps Staff rgruian
PowerApps Staff

Re: Date Expression - Text Label vs. Text Input?

What Andy pointed out is correct. string & date will coerce the right hand side (a date numeric value) to a string using a predefined format. If you need to use a specific format, you need to perform that projection from date/value to text yourself.

 

In the label:

"Date/Time: " & Text(Now(), "mm/dd/yyyy hh:mm:ss")

 

 

Radu Gruian [MSFT] ** PowerApps Staff
audrieg
Level 10

Re: Date Expression - Text Label vs. Text Input?

That works perfectly Andy!! Thanks so much to both of you.

Helpful resources

Announcements
firstImage

PowerApps Monthly Community Call!

Join us next Wednesday for our Demo Extravaganza, October 16, 2019 8am PDT.

firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

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

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Top Kudoed Authors
Users Online
Currently online: 391 members 4,847 guests
Please welcome our newest community members: