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.
I think the problem isn't scope, but how do you create the objDate! I've done a few tries, and that error come up when objDate is a String. So, this snippet of code works as expected, the problem is the parameter passed to DateTimeFormat: I think it'is created like this objDate = Date() instead of objDate = new Date(). The latter will correctly create a Date object instead of returning date in a String format.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With