Javascript cookie "Type Mismatch" solution

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top