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

DateTimeValue in Chrome Error

I stumbled across a weird error with the function DateTimeValue in different browsers and I wondered if anyone could help.

In Microsoft Edge the DateTimeValue function works and displays correctly the value, but in Google Chrome, the DateTimeValue value does not appear. Am I doing something wrong?

 

PAError1.PNGFunction Label 1PAError2.PNGFunction Label 2PAErrorEdge.PNGEdge

PAErrorChrome.PNGChrome

 

In the first and the second picture you see the function in each of the labels. The picture 3 is what is displayed in Edge and in 4, Chrome. 

As you can see, DateTimeValue doesn't seem to work on Google Chrome, does nyone have any insight on what might be causing this error?

 

Thank you!

2 ACCEPTED SOLUTIONS

Accepted Solutions
Super User
Super User

Re: DateTimeValue in Chrome Error

Hi @Anonymous 

In answer to the question "does anyone have any insight on what might be causing this error?", this is what I believe happens. When we call the DateTimeValue function from PowerApps, it calls the underlying date parse methods in JavaScript to carry out the string to date conversion.

The script implementation in Chrome works in a peculiar fashion because as you've discovered, if you include spaces around the hyphen before the time element, the conversion fails.

In the screenshot below, I attempted to declare new dates in JavaScript through the console in developer tools.

image.png

This confirms that Chrome doesn't correctly parse datetimes where there are spaces before and after the hyphen.

Therefore, it seems to me that most compatible format that works across all browsers is to not include a hyphen between the date and time when using DateTimeValue. Eg..

 

DateTimeValue(Text(Today(),"[$-en-US]mm/dd/yy") & " " & "00" & ":" & "00")

Perhaps this is something that you could experiment with?

 

@iAm_ManCat - I agree with what you said about the various frameworks, and thanks for sharing the test app. Very helpful as always 🙂

View solution in original post

Anonymous
Not applicable

Re: DateTimeValue in Chrome Error

tl:dr - Don't try forcing a format before the DateTimeValue function, only force it after if need be

 

Good find @iAm_ManCat , I did in fact encounter this bug earlier when I was testing on a french language browser (since I am developping for a Canadian audience I can't assume that everyone is using an english browser)

 

April 16, 2019 -> 4/16/2019 -> (browser thinks it is dd/mm/yyyy) 4/(16-12)/(2019+1) -> 4/4/2020

 

What seemed to work was removing the formating of the date all together (it will give a different formating between browsers, but the DateTimeValue will always work as expected)

 

If formating there needs to be, do it at the DateTimeValue(Date, FORMAT) level, not the Text(Date,FORMAT) level.

 

Code for label:

Text(Today()) & " " & "00" & ":" & "00"

"DATE: " & DateTimeValue(Label2.Text)

 

DateTimeEdge.PNG

 

DateTimeChrome.PNG

 

DateTimeIE.PNG

View solution in original post

10 REPLIES 10
Super User
Super User

Re: DateTimeValue in Chrome Error

I was able to recreate your issue (& extend it to another potential case below) - it looks like Chrome is the only browser able to automatically convert DateTimeValue properly as a value for the Text part of a Label..

- I'm not 100% sure on this but I would hazard a guess that it might be to do with the way the html5 is being processed by the browser?

 

@timl & @Mr-Dang-MSFT Any ideas as to reasoning behind this one?

 

Labels I used were:

Text(Today(), "[$-en-US]mmmm dd, yyyy")

DateTimeValue(Text(Today(), "[$-en-US]mmmm dd, yyyy") & "-" & "00" & ":" & "00" )

DateTimeValue(Today() & "-" & "00" & ":" & "00" )

 

Screenshot below and I attached the test .msapp

 

image.png

 

Side Note to @Anonymous : if you're using that datetimevalue As a datetimevalue then fair enough, convert it to datetime, but if you're just trying to achieve the "April 12, 2019 12:00" formatting then you can use:

 

Label1.Text = Text( StartDP.SelectedDate, "[$-en-US] mmmm dd, yyyy") & " - " & StartHrDD.Selected.Value & ":" StartMinDD.Selected.Value )

 

Cheers,

ManCat


@iAm_ManCat
Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!

Thanks!
You and everyone else in the community make it the awesome and welcoming place it is,
keep your questions coming and make sure to 'like' anything that makes you 'Appy
Sancho Harker, MVP


Anonymous
Not applicable

Re: DateTimeValue in Chrome Error

So the error that you found is not QUITE the same as I have, in my case I feel like certain browsers don't recognize the format of certain date times when using the DateTimeValue function. For example, look at the difference when I use a space around the "-" betweend the date and the time.

 

Code of the label

DateTimeValue(Text(Today(),"[$-en-US]mmmm dd,yyyy") & "-" & "00" & ":" & "00") & " --- mmmm dd,yyyy-00:00
" & DateTimeValue(Text(Today(),"[$-en-US]mmmm dd,yyyy") & " - " & "01" & ":" & "00") & " --- mmmm dd,yyyy - 00:00
" & DateTimeValue(Text(Today(),"[$-en-US]mm/dd/yy") & "-" & "00" & ":" & "00") & " --- mm/dd/yy-00:00
" & DateTimeValue(Text(Today(),"[$-en-US]mm/dd/yy") & " - " & "00" & ":" & "00") & " --- mm/dd/yy - 00:00"

 

PADTChrome.PNGChrome

 

PADTEdge.PNGEdge

 

As you can see for Edge, the importance is on the Date format, but for Chrome it is on the spacing around the "-" between the date and the time.

 

Weird...

Anonymous
Not applicable

Re: DateTimeValue in Chrome Error

And it is not just the transformation of the DateTimeValue to a text on the label. The issue is that is does NOT create a DateTimeValue at all, since I am feeding it to an SQL server, I see that there is no date being sent.

Super User
Super User

Re: DateTimeValue in Chrome Error

I get what you are saying and I agree - so we have uncovered two separate but similar errors - worth also noting that your Edge dates are showing 1919 when using the short-form 'yy' whereas chrome showed 2019 for the same 3rd line.

 

I still feel like there's a difference in the way the form/item/label/whatever is being interpreted by the browser - this would then result in the item not having a datetimevalue created at all if there were errors that prevented it within the form that are browser-dependant rather than app-dependant, i.e long before it even reaches the data source.

 

PowerApps are crafted with HTML, Javascript and JSON as their frameworks, so one of those three is at fault. The problem likely is where they've done cross-browser compatibility and this probably never came up as a case during QA/testing.


@iAm_ManCat
Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!

Thanks!
You and everyone else in the community make it the awesome and welcoming place it is,
keep your questions coming and make sure to 'like' anything that makes you 'Appy
Sancho Harker, MVP


Super User
Super User

Re: DateTimeValue in Chrome Error

@TopShelf-MSFT just flagging in case this issue is not a known one


@iAm_ManCat
Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!

Thanks!
You and everyone else in the community make it the awesome and welcoming place it is,
keep your questions coming and make sure to 'like' anything that makes you 'Appy
Sancho Harker, MVP


Super User
Super User

Re: DateTimeValue in Chrome Error

Hi @Anonymous 

In answer to the question "does anyone have any insight on what might be causing this error?", this is what I believe happens. When we call the DateTimeValue function from PowerApps, it calls the underlying date parse methods in JavaScript to carry out the string to date conversion.

The script implementation in Chrome works in a peculiar fashion because as you've discovered, if you include spaces around the hyphen before the time element, the conversion fails.

In the screenshot below, I attempted to declare new dates in JavaScript through the console in developer tools.

image.png

This confirms that Chrome doesn't correctly parse datetimes where there are spaces before and after the hyphen.

Therefore, it seems to me that most compatible format that works across all browsers is to not include a hyphen between the date and time when using DateTimeValue. Eg..

 

DateTimeValue(Text(Today(),"[$-en-US]mm/dd/yy") & " " & "00" & ":" & "00")

Perhaps this is something that you could experiment with?

 

@iAm_ManCat - I agree with what you said about the various frameworks, and thanks for sharing the test app. Very helpful as always 🙂

View solution in original post

TopShelf-MSFT Community Champion
Community Champion

Re: DateTimeValue in Chrome Error

Thanks for the tag @iAm_ManCat and also thank you and @timl for your help with this thread. 

 

@Anonymous can you advise if the above reply has helped your progress with this issue?

 

@TopShelf-MSFT 

Anonymous
Not applicable

Re: DateTimeValue in Chrome Error

Thank you @timl  and @iAm_ManCat  for all your help!

 

I followed your recommended format Tim and everything works fine now! 

@TopShelf-MSFT  Maybe it would be benificial to put this format somewhere in the DateTimeValue documentation?

Super User
Super User

Re: DateTimeValue in Chrome Error

Well, the plot thickens! When using other browsers than Chrome, you could potentially have false data entered into a database without knowing, especially if those items were non-visible!

 

So I've fiddled around with four different browsers (App attached as per usual) using the formula you suggested (space only, no hyphen), and a further one using yyyy in case this was the reasoning for the 2020 date, however here are the results:

image.png

 

Formulae used (in order of appearance above):

 

Text(Today(), "[$-en-US]mmmm dd, yyyy")

 - Chrome

  • April 16 2019

 - Firefox

  • April 16 2019

 - Edge

  • April 16 2019

 - Internet Explorer

  • April 16 2019

 

DateTimeValue(Text(Today(), "[$-en-US]mmmm dd, yyyy") & "-" & "00" & ":" & "00" )

 - Chrome

  • 4/16/2019 12:00 AM

 - Firefox

  • 16/04/2019 00:00
  • UK date format?

 - Edge

  • Blank/Invalid

 - Internet Explorer

  • Blank/Invalid

 

DateTimeValue(Today() & "-" & "00" & ":" & "00" )

 - Chrome

  • 4/16/2019 12:00 AM

 - Firefox

  • Blank/Invalid

 - Edge

  • Blank/Invalid

 - Internet Explorer

  • Blank/Invalid

 

DateTimeValue(Text(Today(),"[$-en-US]mm/dd/yy") & " " & "00" & ":" & "00")

 - Chrome

  • 4/16/2019 12:00 AM

 - Firefox

  • 04/04/2020 00:00
  • Incorrect Day
  • Incorrect Year

 - Edge

  • 04/04/2020 00:00
  • Incorrect Day
  • Incorrect Year

 - Internet Explorer

  • 04/04/2020 00:00
  • Incorrect Day
  • Incorrect Year

 

 

DateTimeValue(Text(Today(),"[$-en-US]mm/dd/yyyy") & " " & "00" & ":" & "00")

 - Chrome

  • 4/16/2019 12:00 AM

 - Firefox

  • 04/04/2020 00:00
  • Incorrect Day
  • Incorrect Year

 - Edge

  • 04/04/2020 00:00
  • Incorrect Day
  • Incorrect Year

 - Internet Explorer

  • 04/04/2020 00:00
  • Incorrect Day
  • Incorrect Year

 

So from this we can gather that effectively Chrome is the only browser that would provide correct data when usingthis format.

 

To re-iterate what I mentioned in the top of this, if anyone is using any fields like this in production and did not do cross-browser testing, they may potentially have Apps that are providing false data or not providing any data when writing back to data sources..

 

Could we have this raised as a potential bug?


@iAm_ManCat
Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!

Thanks!
You and everyone else in the community make it the awesome and welcoming place it is,
keep your questions coming and make sure to 'like' anything that makes you 'Appy
Sancho Harker, MVP


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!

Power Platform 2020 release wave 1 plan

Power Platform 2020 release wave 1 plan

Features releasing from April 2020 through September 2020

Top Solution Authors
Top Kudoed Authors
Users online (8,715)