1

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.

7
  • 1
    link or fiddle please ? Commented Apr 27, 2017 at 8:41
  • 2
    "but the output is reversed" — What do you mean by "output"? Are you reading the value with JavaScript? (That's the only programming language you've tagged). Is it client side JS? Are you talking about the submitted form data? Commented Apr 27, 2017 at 8:43
  • "this could lead to problems for the contract form" — What problems? You've defined the solution you want, but not the problem. See meta.stackexchange.com/questions/66377/what-is-the-xy-problem and xyproblem.info Commented Apr 27, 2017 at 8:44
  • yes ofcourse i am talking about the submitted form. thats why i said the posted values. Commented Apr 27, 2017 at 8:45
  • 1
    You're trying to solve the wrong problem. The user interface for a date field is localised to the user's preferences. The submitted value is standardised and easily machine parsable. Just parse the submitted data on the server, then you can present it in whatever for you like. Commented Apr 27, 2017 at 8:47

2 Answers 2

3

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));
    }
Sign up to request clarification or add additional context in comments.

1 Comment

solved it already by myself the exact same way. thats the correct answer
2

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).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.