Javascript policy: set a variable based on whether a date falls within two other dates.

How to set variable in javascript by using time.

I want to set variable between march 2nd sunday to November 1st sunday.

How to get time and date variable in js and set to that above mentioned time.

0 3 116
3 REPLIES 3

You may want to follow the example shown here.  For example

var now = new Date();
var march1st = new Date(now.getFullYear(), 2, 1);
var november2nd = new Date(now.getFullYear(), 10, 2);
if (now < march1st) {
  // it's before march 1st
}
if (now > november2nd) {
  // it's after November 2nd
}
// etc

 

Also, I think you need to take some extra care with your requirements.  March 2nd is not always Sunday, and November 1st is not always Sunday. 

So you need to be careful about what you really want. The first Sunday in March?  Or actually March 1st?  or... ?

I wanted to check second sunday in march and first sunday in november and need to apply quota limit in between this period for 12am to 6am EST.

Oh! I see.  I had misread your original post. That makes sense. 
Searching around, I found this gist for you.