I have a text field where you can enter a date in the format dd/mm/yyyy, and I want to convert that date as yyyy-mm-dd to store in my database.
I know this has been asked many times before, and a common answer is trying something like this.
$var = '20/04/2012';
$date = str_replace('/', '-', $var);
echo date('Y-m-d', strtotime($date));
The problem is I do not know how to apply that to my situation.
This is the code I have in my view
<input type="text" name="initialDate" value="<?php echo $this->input->post('fechaElaboracion'); ?>" class="form-control" id="initialDate" />
In my controller I get all the data from the input fields in my form, save them in an array and then call a function in my model to store them in the database.
$params = array(
'name' => $this->input->post('name'),
'address' => $this->input->post('address'),
'initialDate' => $this->input->post('initialDate'),
);
$po_general_id = $this->Pogeneralmodel->add_po_general($params);
redirect('po_general/index');
Do I need to reformat the date in the view or in the controller? How can I do it? Thanks.