I am using an HTML 5 form on an iPhone. This form has an input element like the following:
W
The following should do it.
$dat = new DateTime($_POST['MyDATE']);
$new_format = $dat->format('Y-m-d');
No.
There are two formats at play:
You cannot change the display format. It's up to the browser to decide how the date is presented to the user (in practice it's determined by system's locale).
You cannot change the internal format either. It's always ISO8601, regardless of browser/locale.
I always thought the format was meant to be YYYY-MM-DD
.
W3C spec & RFC3339.
Anyway, you could convert it with JavaScript.
var dateInput = document.getElementById('birthdate');
dateInput.addEventListener('change', function() {
dateInput.value = new Date(dateInput.value).toISOString().split('T')[0];
}, false);
I agree with @PorneL's answer, however, you can potentially do some work to simulate the results you want. I will stipulate that it's not the best way to do it.
In pseudo code:
Again, it may not be the best solution, but it can work this way.