Gabbax0r
Gabbax0r

Reputation: 1826

html5 date field input is correct but output is reversed

if have the following problem. in my html5 datefield, i have the input order dd.mm.yyyy (for example todays date: 27.04.2017).

<input type="date" />

thats correct in my country and timezone. the posted value is in reversed order to my input. its yyyy-mm-dd (for example todays date: 2017-04-27).

is there any way to change the timeformat if the the value is posted?

ive found several solutions but only for the input and not the posted values.

Upvotes: 1

Views: 451

Answers (2)

Oussama Ben Ghorbel
Oussama Ben Ghorbel

Reputation: 2129

I'm not really sure what you mean but here is something you can try

   $time = strtotime($_POST['dateInput']);
    if ($time != false) {
      $mydate = date('d-m-Y', $time));
    }

Upvotes: 3

Quentin
Quentin

Reputation: 944052

is there any way to change the timeformat if the the value is posted?

The field submits using a standard format. This is consistent across browsers that support the date input type and is required by the standard.

The user interface, on the other hand, is not consistent across browsers.

You can reliably expect a date field to always submit in the form YYYY-MM-DD so you can write a parser for it in your server side code (and then format it however you like).

Solve this problem on the server.

(You /could/ use JavaScript to parse the date, format it, and write it to a hidden input every time the date input changes … but doing it server side is simpler).

Upvotes: 2

Related Questions