When my sproc returns a null, it goes into a C# DateTime as a MinDate. If a date of this form gets to the front end (MVC/Razor), I create a “MinDate” type of my own in JavaScript for comparison. If they match, I want to return an empty string from the JavaScript function. However, although the two dates match, the branch of my “if” statement that returns the empty string is never entered. I’ve looked at these two dates until I’m cross eyed and they appear to match. Why is my function returning the MinDate and not the empty string? (By the way, the “toString()” method is from the DateJS library.)
// Setup a minDate to mimic C#'s Date.MinDate constant.
var minDate = new Date();
minDate.setFullYear(1, 0, 1);
minDate.setHours(0, 0, 0, 0);
function checkDateWithConfig(d, c) {
alert("Date: " + d);
alert("minDate: " + minDate);
if (d == minDate) {
alert("dates matched");
return "";
}
else
{
return d.toString(c);
}
}


Javascript
Dateobjects are references.You cannot use
==to check whether twoDateobjects represent the same value.Instead, compare the
getTime()method on both dates, which returns a number.