i can't insert the values from my JQuery Datepicker to my MySQL database with Date datatype. how will i convert string to date datatype? im using Codeigniter with MVC. here's my code:
javascript
<script>
$(function() {
$( "#datepicker" ).datepicker({
showOn: "button",
buttonImage: "images/icons/calendar_24.png",
buttonImageOnly: true,
onSelect: function(dateText, inst){
$("input[name='dob']").val(dateText);
}
});
});
</script>
controller
function create()
{
$data = array(
'FirstName' => $this->input->post('fname'),
'DateofBirth' => $this->input->post('dob')
);
$this->site_model->add_record($data);
$this->index();
}
view
<?php echo form_open('site/create');?>
<p>
<label for="fname">First Name:</label>
<input type="text" name="fname" />
</p>
<p>
<input type="text" name='dob' id="datepicker" />
</p>
thanks guys! i read some solution in google and i did this:
controller:
function create()
{
$date = $this->input->post('dob');
$data = array(
'FirstName' => $this->input->post('fname'),
'DateofBirth' => date('Y-m-d', strtotime($date))
);
$this->site_model->add_record($data);
$this->index();
}
and this solved my problem! :)
YYYY-MM-DDranging from1000-01-01to9999-12-31. Just convert the date received to this format (if needed) and insert it.