I want to get the timestamp in data table . how to format my datetime in the jquery datatable function?
sql server datatime data, how to edit the columns so that i cant get the proper datetime in the data time. i have tried with type: 'date-dd-mmm-yyyy', but its not working
2018-11-23 07:49:35.073
data type - date time
javascript
$(document).ready(function () {
$('#myTable').DataTable({
"ajax": {
"url": "/Temperature/loaddata",
"type": "GET",
"datatype": "json"
},
"columns": [
{ "data": "id", "autoWidth": true },
{ "data": "updatedDate", "autoWidth": true, type: 'date-dd-mmm-yyyy', targets: 0 },
{ "data": "deviceid", "autoWidth": true },
{ "data": "devicename", "autoWidth": true },
{ "data": "temp", "autoWidth": true },
{ "data": "faht", "autoWidth": true }
]
});
});
c# code
public ActionResult loaddata()
{
using (smartpondEntities dc = new smartpondEntities())
{
var data = dc.Temperatures.OrderBy(a => a.id).ToList();
return Json(new { data = data}, JsonRequestBehavior.AllowGet);
}
}
json sample data
[{"id":1,"updatedDate":"2018-11-23T07:49:35.073","DeviceTime":null,"deviceid":1,"devicename":"aaaa","temp":28.50,"faht":87.90},{"id":2,"updatedDate":"2018-11-23T07:49:42.1","DeviceTime":null,"deviceid":1,"devicename":"aaaa","temp":28.50,"faht":87.90}]
output
/Date(1542939575073)/
exp op
23 Nov 2018 13:10:10
i use moment.js for datetimes (docs). so in your render:
{
title: "Date",// name
render: function (data, type, row) {//data
return moment(row.updatedDate).format('DD/MM/YYYY hh:mm:ss');
}
}