Click to See Complete Forum and Search --> : DATE function giving an extra "0" for Oct.


cygnusx1z
10-01-2003, 09:05 AM
I have a script that inputs "today's" date into a text field. Today is October 1st and it seems I did something wrong because the date is showing up as 010/01/2003.

My code is:

Date.prototype.toString = function () {return [this.getMonth() < 10 ? '0' + (this.getMonth()+1) : (this.getMonth()+1), this.getDate() < 10 ? '0' + this.getDate() : this.getDate(), this.getFullYear()].join('/')}


Thanks in advance.

Khalid Ali
10-01-2003, 09:27 AM
this should work

Date.prototype.toString = function () {return [(this.getMonth()+1) < 10 ? '0' + (this.getMonth()+1) : (this.getMonth()+1), this.getDate() < 10 ? '0' + this.getDate() : this.getDate(), this.getFullYear()].join('/')}

cygnusx1z
10-01-2003, 09:42 AM
Thanks Again Khalid! It worked perfectly.

Khalid Ali
10-01-2003, 09:55 AM
;)
glad to be of help

Charles
10-01-2003, 01:27 PM
Wouldn't

Date.prototype.toString = function () {return [this.getMonth() < 9 ? '0' + (this.getMonth()+1) : (this.getMonth()+1), this.getDate() < 10 ? '0' + this.getDate() : this.getDate(), this.getFullYear()].join('/')}

have been easier?