0

I'm puzzled as to why safari can only use the date format of YYYY-dd-mm. Is this a common issue? I want the format to be mm-dd-yyyy.

ThomasBrushel
  • 107
  • 3
  • 16

2 Answers2

0

There's no date format as of now! You should pick a date picker plugin for this solution.


Ambiguous solution: use pattern which will show error on form submission though message of the date format seems different.

All about input type date

Example from MDN

<input type="date" id="bday" name="bday" required
 pattern="[0-9]{4}-[0-9]{2}-[0-9]{2}">
Bhojendra Rauniyar
  • 83,432
  • 35
  • 168
  • 231
  • So your saying it's not possible to use the date format of `mm/dd/yyy` or `MM-dd-yyyy` in Safari? And that it's only possible to use `yyyy-dd-mm` ? – ThomasBrushel Feb 13 '18 at 17:40
  • I was trying to prevent using a datepicker plugin. I'm using this package from yarn. https://yarnpkg.com/en/package/date-input-polyfill – ThomasBrushel Feb 13 '18 at 17:42
0

For input type "date", value that would be set is always in format of "yyyy-mm-dd" where as the display format depends on locale of user's browser

Ref: MDN Date Input

  • So your saying it's not possible to use the date format of `mm/dd/yyy` or `MM-dd-yyyy` in Safari? And that it's only possible to use `yyyy-dd-mm` ? – ThomasBrushel Feb 13 '18 at 17:40
  • I was trying to prevent using a datepicker plugin. I'm using this package from yarn. https://yarnpkg.com/en/package/date-input-polyfill – ThomasBrushel Feb 13 '18 at 17:43
  • Just to clarify again what you display to the user after the date is selected can be of any format but what you eventually get from 'value' of input elem is only in the format of 'yyyy-mm-dd'.(E.g when submitting form with date input field) – Sudheendra chari Feb 14 '18 at 18:22
  • How would you display a different format to the user after the date is selected though? I'm lost. When I try to add 06/29/1995 it doesn't accept it. – ThomasBrushel Feb 14 '18 at 19:39
  • I finally got the date to show up in safari by doing . ` data.birth_date = new Date("#{data.birth_date.replace(/-/g,"/")}")` but it's still in 1992-06-27 format – ThomasBrushel Feb 14 '18 at 19:40