The $model->datetime is d-m-Y H:i:s.
<?php echo $form->textField($model,'datetime'); ?>
I would like the value of the input just be d-m-Y, how can I format it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
One option would be to convert the date to a human readable format to display it, and then back to the format needed by the database before you save. You could edit/create the
afterFind()method in your model to convert the date to a human readable format, something like so:And again before you save by editing/creating your model’s
beforeSave()method, for example something like:Note that when you save, the hour, minute and second will always be 0 in the examples above. You’d also need to put some validation to make sure your user input was in the correct d-m-Y format too, or the date conversion won’t work.
*Fixed typo newdate->newDate