Problem with date to display in CakePHP 3.8 form field

I have a problem that I want to show the date in the Spanish format dd/MM/yyyy inside the form field but I can’t do it, I have modified the frozendate in bootstrap, in appcontroller, I have looked at what the request returns before and after the patchentity but there is no way to format it.

The message displayed is this in the browser inspector console: “The specified value” 10/9/20 “does not conform to the required format,” yyyy-MM-dd “.”

Does anyone know what steps to follow to modify FrozenDate or Date and that the date is displayed correctly within the input from the database.

Thank you very much for the help

1 Like

I believe the Danish format is the same and I am experiencing the same challenge, so I would be grateful if someone has the answer for this :pray:

It sounds like you are only trying to adjust the Time object in the belief that it will change the form inputs. But those are actually under your control:

I have not needed to change the default input templates my self so I don’t have first-hand knowledge, but I believe this is what you want

Also, searching the formum for ‘form template’ will return many posts which may help

@debito : Are you using CakePHP 3 or 4?

Are you trying to display the value from database (formatted as yyyy-mm-dd) as your locale dd-mm-yyyy?

CakePHP 3

You need to change the date-widget template in the FormHelper as @dreamingmind mentioned.

You can do that by adding this to your src/View/AppView.php file:

$this->loadHelper('Form', [
    'templates' => [
        'dateWidget' => '{{day}}{{month}}{{year}}{{hour}}{{minute}}{{second}}{{meridian}}'





CakePHP 4
I could not replicate the issue in Cake 4 as the form is displayed by the locale of my browser (checked Firefox and Chrome). When using my Norwegian locale, it as displayed as dd-mm-yyyy. When I changed to English (US) it was displayed as mm-dd-yyyy

1 Like

I am using CakePHP 3.

Thank you very much for the answer! :pray:
You nailed the challenge and it solved my problem. Thanks!

1 Like