$dateFormat property of class yii\i18n\Formatter does not work, because date fields on a form are not displayed in the format ‘dd.MM.yyyy’ but in the normal format ‘yyyy-MM-dd’.
Instead the $nullDisplay property does its job showing the correct value set, i.e. showing ‘(Non impostato)’
I will have to do the same thing in all views where the date is displayed.
However I still do not understand why acting on the Formatter does not work …
… ok, in fact I would like to leave the y-m-d format in the table but in the DatePicker only show the d-m-y format (I hope I was clear, sorry but I’m not very familiar with yii)
Ok, but if I do this then the date in this format does not pass the validator check and I get the message “The format of Data Sentenza is invalid” … because the validator expects the date in yyyy-MM-dd format … (I know I’m doing something wrong …)
If, on the other hand, I set both the format of the validator and that of the DatePicker to dd-MM-yyyy I have no problems neither in displaying the form nor in validation but … then in the DB I end up with the value 0000-00-00! which is obviously not acceptable …
You’re right, I’ve made a bit of confusion, I realized, thanks to you, that the Formatter has nothing to do with it.
So I try to summarize my problem more clearly:
In a Date field on a form I would like to display the date in dd-MM-yyyy format
Hi,
That sounds to me like the database is rejecting wrong format replacing it with default 0000-00-00
So if it is really important to you, you need to reformat your model code to format that database understands in beforeSave() method of your Model and then reconvert for display in afterFind() method of the same