Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8127771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:38:56+00:00 2026-06-06T07:38:56+00:00

I am using a function which sets a cookie. This function allows the cookie

  • 0

I am using a function which sets a cookie. This function allows the cookie name, the cookie value and an additional expiry date of the cookie to be passed into it.

function setCookie(name, value, exdate) {
    var c_value = escape(value) + 
      ((exdate === null || exdate === undefined) ? "" : "; expires=" + exdate);
    document.cookie = name + "=" + c_value;
};

Usage:

setCookie("my-cookie-name","my-value","Sun, 15 Jul 2012 00:00:01 GMT");

I have used the function with the date format above and believe it is cross browser compatible as I have tested if the cookie remains after closing various browsers and reopening them. I discovered that there were problems when using a format like "15 Jul 2012". This format worked for me during development in Firefox, but other browsers only seemed to set the cookie as a session cookie.

Should I stick to using just this format: "Sun, 15 Jul 2012 00:00:01 GMT" or are there other formats I could use for the expiry date that will work across the major browsers (IE 7-9, Firefox, Chrome, Opera, Safari)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T07:38:58+00:00Added an answer on June 6, 2026 at 7:38 am

    Based on testing and further reading into this, a date in a UTC/GMT format is required by cookies e.g. Sun, 15 Jul 2012 00:00:01 GMT

    Therefore any dates in other formats such as 15 Jul 2012, or 15/Jul/2012, or 07/15/2012, have to be passed as a new Date object and then through the toUTCString() or the toGMTString() function.

    therefore I have edited my function to the following:

    function setCookie(name, value, exdate) {
        //If exdate exists then pass it as a new Date and convert to UTC format
        (exdate) && (exdate = new Date(exdate).toUTCString());
        var c_value = escape(value) + ((exdate === null || exdate === undefined) ? "" : "; expires=" + exdate);
        document.cookie = name + "=" + c_value;
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my code for setting a cookie: function setCookie(c_name, value, expiredays) { alert(setting
Windows API offers InterlockedExchange , which sets a value in memory atomically. Using only
There is a function which sets an interval using setInterval() , but even after
I'm using a function which utilizes jQuery in order to grab information from a
How to call a function which takes two parameters using threading in C#? I
I've written a function which makes an asynchronous request using jQuery. var Site =
I already managed to create function which checks if user is using a trial/demo
[using MacVim 7.3 on OS X Lion] I have a vimscript function which runs
I wrote the function using js+jQuery. Here is a link to a jsFiddle which
I am using a library function called get_count_and_price which returns a 2-tuple (count,price). In

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.