1

I need to be able to set a cookie and have it expire every saturday using Javascript but not sure where to begin.

var now = new Date(); var day = now.getDay();

document.cookie =

Pdavis33
  • 49
  • 7

1 Answers1

0

First you have to define next Saturday this way.

var nextSaturday = new Date();
nextSaturday.setDate(nextSaturday.getDate() + (6 + 7 - nextSaturday.getDay()) % 7);

if you console.log(nextSaturday) it will give you the date of next Saturday. Then you can store your cookie like this:

document.cookie = "myCookie=ok; expires=" + nextSaturday;
dimitris tseggenes
  • 3,031
  • 2
  • 16
  • 23