date field is not updated!

I printed out the actually model post attributes as below

Array (

[subject] => I would like to Reserve

[is_read] => 0

[ReservationDate] => 22/10/2014

[body] => sdfsdf [id] => [sender_id] => [receiver_id] => [Vessel_Vesselid] => [deleted_by] => [created_at] => )

$model->save() calls successfully which saves all the fields in the database

but the date is not saved in database!! (see Reservationdate)

I am using MySQL and datatype is Date

5976

Screen Shot 2014-10-10 at 9.13.47 PM.png

Dates in mysql are usually formatted as Y-m-d (or Y-m-d H:i:s for DateTime). You probably need to reformat your entered dates before it reaches your database. You can do this in your model, maybe inside your model’s beforeSave() method




public function beforeSave()

{

	if (parent::beforeSave())

	{

		if ($this->ReservationDate !== null)

		{

			$this->ReservationDate = date('Y-m-d', strtotime($this->ReservationDate));

		}

		return true;

	}

	return false;

}



or something similar like that

Ah Thanks!! I guess that should work

Unfortunately it stores the date but wrong date as " 1970-01-01"

Found a solution for this

date(‘Y-m-d’, strtotime(str_replace("/","-",$this->ReservationDate)));