There are some things to know about Bootstrap datepicker.
First it isn't made to handle form submit event so when you set your data-date-format="dd MM yyyy - HH:ii p", you are getting exactly that POST string. That means a preprocess are needed.
You can do so by the client side or sever side. Always is better work in client side so save resources of our server. You can build also a function inside your PHP to convert to MySQL format your POST string.
Remember if you process at client side you need to send the POST in MySql Format(YYYY-mm-dd for DATE) or (YYYY-mm-dd H:i:s for DATETIME or TIMESTAMP)
Ex.:
// Format your datetimepicker with Mysql format
$("input[name='date_from']").datepicker().on('changeDate', function(e){
var dateFrom = new Date(e.date.getFullYear(), e.date.getMonth(), e.date.getDate(), e.date.getHours(),e.date.getMinutes(),0);
});
Now you can push this value on a hidden field:
HTML:
<input id="sqldate_from" type="hidden" name="sqldate_from" />
SCRIPT:
$("input[name='date_from']").datepicker().on('changeDate', function(e){
var dateFrom = new Date(e.date.getFullYear(), e.date.getMonth(), e.date.getDate(), e.date.getHours(),e.date.getMinutes(),0);
});
$("#sqldate_from").val(dateFrom);
PHP:
$date_from = $_POST['sqldate_from'];
You also can get the original string without treatment and process in PHP...something like this (only for YYYY-mm-dd format):
public function formatDatepickerToMySql($date) {
if ($date != FALSE) {
$dateArr = explode("-", $date);
$newDate = $dateArr[2] . '-' . $dateArr[1] . '-' . $dateArr[0];
return $newDate;
}
return FALSE;
}
Hope be usefull
KR
apassos
The TIMESTAMP data type is used for values that contain both date and time parts. TIMESTAMP has a range of '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC.YYYY-MM-DD HH:MM:SSformat for SQL.