I need to convert a date object into a string that SQL Server will understand. This is what I have so far:
(function() {
Date.prototype.MMDDYYYY = function() {
var month, day, year;
month = String(this.getMonth() + 1);
if (month.length === 1) {
month = "0" + month;
}
day = String(this.getDate());
if (day.length === 1) {
day = "0" + day;
}
year = String(this.getFullYear());
return month + '/' + day + '/' + year;
}
})();
(function() {
Date.prototype.HHMMSS = function() {
var hour, minute, second;
hour = String(this.getHours());
minute = String(this.getMinutes());
second = String(this.getSeconds());
return '' + hour + ':' + minute + ':' + second;
}
})();
function DateTimeFormat(objDate) {
return objDate.MMDDYYYY() + ' ' + objDate.HHMMSS();
}
The error I’m getting is:
Object Tue Jan 29 … (Eastern Standard Time) has no method MMDDYYYY.
It might be obvious, but I don’t understand how to prototype.
Using jQuery is acceptable.
The problem is that you are passing a string to the function
DateTimeFormat.You can ensure it’s a date object by adding this…