I am working on an MVC application that retrieves data from a SQL database and passes it to a view. One of the views contains a Kendo grid that displays the data, including a date column. The date data is stored in the SQL database as DateTime, while the model in the application uses the variable DateTime? When the data is passed to the view, the date column is formatted like this:
columns.Bound(sc => sc.RefundDate).Width(10).Title("Refund Date").Format("{0:MM/dd/yyyy}");
The displayed date format looks correct, for example, March 7, 2023, is displayed as 03/07/2023.
I am now setting up an AJAX call to the controller that triggers when a specific button is clicked. The AJAX call fetches new data and displays it in generic Kendo text boxes. I have a piece of JavaScript code that executes upon succeeding AJAX call:
function SetSmallClaimsDetails(data) {
console.log(data);
$("#SmallClaimsRefundDate").val(data.RefundDate);
}
When the code runs and I check the console log, I see:
Object
ActualRefund: 0
RefundDate: "/Date(1678206755990)/"
I suspect that the date is being converted by JSON. Here's the AJAX call code:
var url = '/Case/GetSmallClaimsByRecordNumber?ID=789456';
$.ajax({
type: 'GET',
url: url,
dataType: 'text',
success: function (data) {
if (data != undefined) {
var jsonData = JSON.parse(data);
jsonData.ID = ID;
SetSmallClaimsDetails(jsonData);
}
}
});
If I modify my JavaScript to this:
function SetSmallClaimsDetails(data) {
console.log(data);
var date = new Date();
if (!data.RefundDate) {
date=''
} else {
date = new Date(parseInt(data.RefundDate.substr(6)));
}
$("#SmallClaimsRefundDate").val(date);
}
The display date changes to:
Tue Mar 07 2023 11:32:35 GMT-0500 (Eastern Standard Time)
How can I make the date display as 03/07/2023?
Appreciate any help. Thank you.