I'm trying to store a date value in a MySQL database using serialize()
. However, the result in the db is treated as "1969-12-31". I'm almost certain it's because of the way the data is being serialized in my ajax call.
Here are the code snippets. Where am I going wrong?
Ajax portion:
data: decodeURIComponent(form.serialize()),
The Result portion of the serialized data is this (when I view the serialized data in console):
&pur-date=2014+/+02+/+31
^ I think the "+" is what's causing the error.
In my model (Codeigniter):
$date = date("Y-m-d", strtotime($this->input->post('pur-date')));
If I replace the strtotime
value to "2014-10-10" for example, the data is correctly stored into the db. So the issue has to be related to the post data coming in.
Note, column type in db is date
.
Anyone?