Why do my rendered date values appear in this format? "/Date(1517900400000)/"
Why do my rendered date values appear in this format? "/Date(1517900400000)/"
I'm trying to show date values in "mm-dd-yyyy" format but all my date values look like this "/Date(1517900400000)/".
I didn't see any .NET MVC examples that fit my scenario (or maybe Google didn't index them in the search engine?).
How can I format my date values as "mm/dd/yyyy"?
My controller code is:
public ActionResult EditorTable(string campus)
{
var settings = Properties.Settings.Default;
var formData = HttpContext.Request.Form;
using (var db = new Database(settings.DbType, settings.DbAttendanceConnection))
{
var response = new Editor(db, "ReconcileSummaryDaysAbsentAndReturned", "Id")
.Model<ReconcileSummaryDaysAbsentAndReturned>()
.Field(new Field("BatchDate"))
.Field(new Field("Reconciled"))
.Field(new Field("Campus"))
.Field(new Field("StudentName"))
.Field(new Field("StudentId"))
.Field(new Field("EntryDate"))
.Field(new Field("ExitDate"))
.Field(new Field("DateAttended"))
.Field(new Field("DaysAbsent"))
.Field(new Field("DurationOfAbsence"))
.Field(new Field("TotalChronicHealthRecordsInSchoolYear"))
.Field(new Field("SbmsTotalDaysSuspendedInSchoolYear"))
.Where("Campus",campus)
.Process(formData)
.Data();
return Json(response, JsonRequestBehavior.AllowGet);
}
}
My relevant view code is:
fields: [
{ label: "Batch Date", name: "BatchDate", type: 'datetime', def: function() { return new Date(); }, format: "mm-dd-yyyy" }, /* ...etc */
Column config:
{ data: "BatchDate", className: 'readonly not-allowed' },/* ...etc */
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
The mystery deepens. Doing this for one date field did the same thing to ALL date fields.
While the tabular data fields rendered in the correct date format, the time component was still included. I need this to be date-only.
Found the answer here: https://datatables.net/forums/discussion/19326/date-time-format
So I wasn't losing my mind -- just had to render the code differenntly.
Update: I found a shorter method that turns out to be more reliable.
In case your datetime is nullable.