D
dmgauntt2002
I have some javascript ASP code that sets the expiry date on a cookie
to five years from now. The code worked until today, when I got the
following error message:
Microsoft JScript runtime (0x800A000D)
Type mismatch
The code was
var expiryDate=new Date();
expiryDate.setYear(expiryDate.getYear()+5);
Response.Cookies(cookieName).Expires=DateToExpires(expiryDate);
function DateToExpires(myDate)
{
return
String(theDate.getMonth())+"/"+theDate.getDate()+"/"+theDate.getFullYear();
}
DateToExpires returns "4/31/2010"; this is the correct format for
Expires.
See the problem? APRIL HAS ONLY 30 DAYS! I forgot that the value of
theDate.getMonth() runs from 0 to 11. The proper code is
function DateToExpires(myDate)
{
return
String(theDate.getMonth()+1)+"/"+theDate.getDate()+"/"+theDate.getFullYear();
}
which returns "5/31/2010" (which is actually 5 years from now!)
I hope that this helps someone.
- David Gauntt
to five years from now. The code worked until today, when I got the
following error message:
Microsoft JScript runtime (0x800A000D)
Type mismatch
The code was
var expiryDate=new Date();
expiryDate.setYear(expiryDate.getYear()+5);
Response.Cookies(cookieName).Expires=DateToExpires(expiryDate);
function DateToExpires(myDate)
{
return
String(theDate.getMonth())+"/"+theDate.getDate()+"/"+theDate.getFullYear();
}
DateToExpires returns "4/31/2010"; this is the correct format for
Expires.
See the problem? APRIL HAS ONLY 30 DAYS! I forgot that the value of
theDate.getMonth() runs from 0 to 11. The proper code is
function DateToExpires(myDate)
{
return
String(theDate.getMonth()+1)+"/"+theDate.getDate()+"/"+theDate.getFullYear();
}
which returns "5/31/2010" (which is actually 5 years from now!)
I hope that this helps someone.
- David Gauntt