Currently, I am facing an issue with formatting dates in a SQL database query that is being serialized by ASP and then converted to JSON for display in Datatables using JavaScript. Instead of the correct date format, I am seeing: /Date(1424563200000)/
.
I have attempted to rectify this problem by implementing the following code snippet:
function ToJavaScriptDate(value) {
var pattern = /Date\(([^)]+)\)/;
var results = pattern.exec(value);
var dt = new Date(parseFloat(results[1]));
return (dt.getMonth() + 1) + "/" + dt.getDate() + "/" + dt.getFullYear();
}
However, I am uncertain how to invoke this function every time my Datatable attempts to read a date.
The configuration of my table is as follows:
$('#YourTaskTable').dataTable({
"ajax": "App_JSON/YourTaskTable.txt",
"columns": [
{ "data": "TName" },
{ "data": "RegistrationNo" },
{ "data": "DueDate"}
]
});
I have tried modifying it like this:
$('#YourTaskTable').dataTable({
"ajax": "App_JSON/YourTaskTable.txt",
"columns": [
{ "data": "TName" },
{ "data": "RegistrationNo" },
{ "data": ToJavaScriptDate("DueDate")} //Function call added here
]
});
Unfortunately, this approach does not seem to be effective as I am still unable to see the formatted date. How can I properly utilize this function to convert the date in this scenario?