0

I have a string searchStartDate coming from an input field on a VF page.

The input is 03/20/2019

Once passed to the apex controller I debug the string before parsing it.

In IE11:

08:02:13:041 USER_DEBUG [1386]|DEBUG|searchStartDate: ‎3‎/‎20‎/‎2019

In Chrome:

08:01:04:058 USER_DEBUG [1386]|DEBUG|searchStartDate: 3/20/2019

When performing Date searchStartDateDate = Date.parse(searchStartDate); IE 11 returns the following error, while Chrome successfully parses the date.

Invalid date: ‎3‎/‎20‎/‎2019

1 Answer 1

2

IE 11 doesn't have great date support. Heres a stackoverflow question about pretty much the same thing:

https://stackoverflow.com/questions/43943879/date-parse-failing-in-ie-11-with-nan

According to MDN docs for Date.parse() parameter:

dateString

A string representing an RFC2822 or ISO 8601 date (other formats may be used, but results may be unexpected).

Looks like Microsoft simply didn't implement the format you provided. I wouldn't use this format anyway, because it's locale dependent(might just be dd/mm/yyyy or sometimes might also fit mm/dd/yyyy).

An alternative to your solution is to use moment.js

Basiclly since IE 11 won't do it out of the box you'll need either some custom code (try looking up polyfills for IE) or a date library.


These are far from the only issues with IE 11 & dates. See this blog post for some other issues.

The ideal solution would be to not use IE 11, but thats not always realistic.

6
  • I'm not sure this is relevant, but maybe I misunderstand. This Date.parse is in Apex, not javascript, isn't this being evaluated on the server/salesforce side, not the browser side?
    – S.B.
    Mar 21, 2019 at 14:13
  • The strings look identical - I would expect 0 differences between the two in apex. Apex runs server side & wouldn't be effected by the browser the client uses. Try looking harder at the variable being passed - there may be some issue that isn't obvious from your post. There should be no difference in behavior on the server side when provided the same inputs. Mar 21, 2019 at 15:48
  • Try an assert(dateString, '03/01/2019');. There may be an issue with the actual text itself being passed along. i still think your best answer is to handle this in the browser itself to ensure apex gets a valid date value. Mar 21, 2019 at 15:50
  • Just a thought, but you might want to try passing not the actual date, but the total number of milliseconds that the date stores internally. Using that value instead of a formatted string might help your code work better cross-platform. Mar 21, 2019 at 16:47
  • 1
    You were in the right domain. Even though the strings looked identical, there were invisible unicode strings in IE 11 due to my use of .toLocaleDateString(); csgpro.com/blog/2016/08/…
    – S.B.
    Mar 22, 2019 at 17:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .