On the form I’m trying to use the CJuiDateTimePicker extension, which provides a date in dd/mm/yyyy hh:ii format, but the database is dd/mm/yyyy hh:ii:ss. So it happens that if I enter the date in a format which is not exactly the one on the database the input is ignored.
how can I parse and format the date before the insert?
I dont know why you dont put the same formats on form and on database.
But if I assume that you have different formats, you could do the following:
Be aware, i didnt test this code
public actionSaveMyDatePicker() {
$modelObject = new MyModel();
if(isset($_POST['MyModel'] === true) {
$modelObject->attributes = $_POST['MyModel'];
//here we validate the model object, to ensure that validation rules are ok (to ensure that we have dd/MM/yyyy HH:mm format)
if($modelObject->validate() === true) {
//if model is validated, we transform here the date
$modelOblect->data_vendita = CDateTimeParser::parse ($modelObject->data_vendita , 'dd-MM-yyyy HH:mm:ss');
//we save withouth checking validation rules
$modelObject->save(false);
}
}
}
Of course, if you can avoid to save without checking validation rules is better. so i suggest to you to implement the functionbeforeSave() in your model (i assume that you are using Active Records) and manage the parsing date on that function.
Well, I do not know this question has been solved or not, but would like to answer for new bee ( like me ) because was facing the same problem and hopefully able to resolved.
check your database format [yyyy.mm.dd hh.mm.ss in my case]