Aaaa-mm-dd date on jquery to insert in DATE in mysql

I have field in my table on the database like this :

|   date_estimate   |
|   YYYY-mm-dd      |

In php that I use d like this :

<input type="text" class="datepicker" id="date" value="<?php echo date("d-m-Y"); ?>">

So, I use ajax in jquery to sent the data from my app. The code is like this :

var id = $("#mainTitle strong").text().split("/").pop();
var StringDate = $('#date').val();
var cDate = StringDate.split("-");
var DateN = new Date(cDate[2],cDate[1]-1, cDate[0]);
console.log(DateN);

$.ajax({
    url: '<?php echo base_url() . 'control_closing/kasihCatatan/' ?>',
    type: 'POST',
    data: {id: id,
           DateN: DateN,
          },
    dataType: 'json',
    success: function(obj) {
          alert('Update Success');
          location.reload();
       }
  });

In firebug, "console.log" gives me :

Date {Thu May 07 2015 00:00:00 GMT+0700 (SE Asia Standard Time)}

So, I failed insert into database. How can I solve this ? Should I convert date on jquery to YYYY-MM-DD. How can I make it true ? Thanks for the help.

Try to change the format with php -

var id = $("#mainTitle strong").text().split("/").pop();
var StringDate = $('#date').val();
$.ajax({
    url: '<?php echo base_url() . 'control_closing/kasihCatatan/' ?>',
    type: 'POST',
    data: {id: id,
           DateN: StringDate,
          },
    dataType: 'json',
    success: function(obj) {
          alert('Update Success');
          location.reload();
       }
  });

On the php page -

$date = date('Y-m-d', strtotime($_POST['DateN']));
我来评几句
登录后评论

已发表评论数()

相关站点

+订阅
热门文章