[thelist] JavaScript date problem

Warden, Matt mwarden at mattwarden.com
Wed Jan 2 11:48:53 CST 2002

>    var Day = leadingZero(today.getDate());
>    var Day = DaySub[today.getDay()];

firtly, you are assigning two different values to the same variable
name. the latter will overwrite the former (though, I would think that
var'ing something twice would throw an error *shrug*).

secondly, getDay() returns the numerical day of the week. Sunday
would be 0, Monday would be 1, Tuesday would be 2, Wednesday would be 3,

The other thing you need to be aware of is that javascript arrays are
0-based. IOW, their first element is myArray[0], not myArray[1]. So, I
believe this is what you really want:

var sOrdinalDate = DaySub[today.getDate()-1];

Then use sOrdinalDate where you want to display the ordinal date (1st,
2nd, 3rd, etc.).

Hope this helps,


More information about the thelist mailing list