To obtain Date only from Datetime
To obtain Date only from Datetime

I am using dataTable for rendering data from Sql Server, but the dateTime format is displayed incorrectly, even though I update the $(document).ready(function () {
//debugger;
$('#New_table').DataTable({
});
$.ajax({
url: '@Url.Action("NewMaterials", "InventoryController")',
type: "post",
dataType: "json",
data: {
},
success: function (response, textStatus, jqXHR) {
console.log(response);
var temp = jQuery.parseJSON(response).Table;
alert(temp);
~~~~
//debugger;
$('#New_table').dataTable().fnDestroy();
$('#New_tabledesign~~~~').dataTable({
"data" : temp,
"destroy": true,
"dateFormat": "yy-mm-dd",
"columns": [
{ "data": "sl.no" },
{ "data": "Materials Name" },
{ "data": "Batch" },
//{ "data" : "ReceivedDate"},
{
"data": "ReceivedDate", 'render': function (dateTime) {
var dateTime = dateTime.split(" ");
var date = dateTime[0].split("-");
var time = dateTime[1].split(":");
return new Date(date[0], date[1], date[2]);
// var tempDate = dataresponse.substr(0, 10);
// alert(tempDate);
// // var date = new Date(parseInt(dataresponse.substr(0)));
//var date = (parseInt(tempDate));
//console.log(date);
//var month = date.getMonth() + 1;
//console.log(month);
//return date.getDate() + "/" + month + "/" + date.getFullYear();
//return dataresponse.substr(9, 10) + "/" + dataresponse.substr(6, 7) + "/" + dataresponse.substr(0,3);
// return dataresponse.substr(0, 1) + "/" + dataresponse.substr(3, 4) + "/" + dataresponse.substr(6,9);
}
},
// I obtain Date time for example in yyyy/mm/dd HH : MM : SS but I want to render only the Date* and discard the time part.
for above instead YYYY/MM/DD should be displayed.~~~~
{......
Details:
O/S Win 7 - Web based application , ASP.NET MVC (HTML 5), use of ajax request
Regards,
VishalK_95
Answers
You need to look at your "render" function.
For example, if that is your Date format, why are you using split("-"); ?