Javascript cookie "Type Mismatch" solution

Discussion in 'ASP General' started by dmgauntt2002@yahoo.com, May 31, 2005.

  1. Guest

    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
     
    , May 31, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. data type mismatch error

    , Aug 10, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    637
    Karl Seguin
    Aug 10, 2005
  2. type mismatch error

    , Aug 12, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    3,365
    Kevin Spencer
    Aug 12, 2005
  3. Artie Gold

    Re: type mismatch

    Artie Gold, Feb 28, 2004, in forum: C Programming
    Replies:
    0
    Views:
    397
    Artie Gold
    Feb 28, 2004
  4. Vikram Bhatia
    Replies:
    1
    Views:
    237
    kaeli
    Oct 11, 2003
  5. programmingzeal
    Replies:
    0
    Views:
    1,124
    programmingzeal
    May 6, 2012
Loading...

Share This Page