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.

Gabbax0r
  • 1,696
  • 3
  • 18
  • 31
  • 1
    link or fiddle please ? – Mhd Alaa Alhaj Apr 27 '17 at 08: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? – Quentin Apr 27 '17 at 08:43
  • "this could lead to problems for the contract form" — What problems? You've defined the solution you want, but not the problem. See https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem and http://xyproblem.info/ – Quentin Apr 27 '17 at 08:44
  • yes ofcourse i am talking about the submitted form. thats why i said the posted values. – Gabbax0r Apr 27 '17 at 08:45
  • Possible duplicate of [Is there any way to change input type="date" format?](http://stackoverflow.com/questions/7372038/is-there-any-way-to-change-input-type-date-format) – Ryad Boubaker Apr 27 '17 at 08: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. – Quentin Apr 27 '17 at 08:47
  • thanks, parsed it in php and format it. – Gabbax0r Apr 27 '17 at 08:56

2 Answers2

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));
    }
Oussama Ben Ghorbel
  • 2,132
  • 4
  • 17
  • 34
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).

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335