Bhargav Makwana Bhargav Makwana - 2 years ago 167
Javascript Question

can't update and create using datepicker in jquery and jtable

I have got problems with date field. When I create a new record or update an existing one, the date field is saved as 000-00-00.

With the datepicker when I select any day ,It is stored in table with value (0000-00-00).

The DB field is date type.

I download the PHP sample code, create a DB with example sql and change the RecordDate field editable and I have the same problem.

DB value: 0000-00-00
JTable shows: 1899-11-30
What should I do?? Please help This is the jquery code:-

$(document).ready(function () {

var assignmentid= "<?php echo $assignmentid; ?>";
//Prepare jTable
title: 'Table of people',
actions: {
listAction: 'teacherfill.php?action=list&aid="<?php echo $assignmentid; ?>"',
createAction: 'teacherfill.php?action=create&aid="<?php echo $assignmentid; ?>"',
updateAction: 'teacherfill.php?action=update&aid="<?php echo $assignmentid; ?>"',
deleteAction: 'teacherfill.php?action=delete&aid="<?php echo $assignmentid; ?>"'
fields: {
lecture_id: {
key: true,
create: false,
edit: false,
list: false
lecture_no: {
title: 'Lecture No',
width: '40%'
lecture_date: {
title: 'Lecture Date',
width: '20%',


//Load person list from server


PHP Code:-

if($_GET["action"] == "update" && $_GET["aid"])

$q="UPDATE lecture_schedule SET lecture_no=$updatedlecno,lecture_date=$updatedlecdate WHERE (lecture_id=$lecid)";
$result = mysqli_query($conn,$q);
$er="No error";

//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
//$jTableResult['status'] = $er;
//$jTableResult['date'] = $updatedlecdate;

print json_encode($jTableResult);

Answer Source

Like so, as per my comment on the date format.

  $DateTime = new DateTime($_POST['lecture_date']);
  $lecture_date = $DateTime->format('Y-m-d');

You have to convert it from m/d/Y to the Y-m-d that the database uses ( ISO 8601 )

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download