1

I volunteer with an animal rescue group and our web site strictly an HTML site with jQuery.

I'm looking for suggestions on how to make this a bit more dynamic so I don't have to figure out when the next adopt-a-pet event will be. They are always on the 2nd and 4th Saturday of each month. With that information, I would expect I could implore a little JavaScript/jQuery magic and produce HTML code, dynamically.

<article class="event-holder">    
<h4><a class="more-heading" href="aap.html">Adopt A Pet</a></h4>    
<p>Meet our cats available for adoption on June 26th... <a class="read-more" href="aap.html">MORE</a></p>    
</article>

Given the code sample above, the date of June 26th would be a dynamic variable. Only thing is I'm not sure where to start.

If I can get some help with this, I'd really appreciate it.

HPWD
  • 2,232
  • 4
  • 31
  • 61
  • There are some answers in [this answer](http://stackoverflow.com/questions/4822852/how-to-get-the-day-of-week-and-the-month-of-the-year). Try a little googling. – Dan Hogan Jun 19 '15 at 17:05
  • @oka Not much. I attempted some google searches but nothing I found quite did what I needed it to do. – HPWD Jun 19 '15 at 17:14

1 Answers1

0

This seems to work for me:

var nextSaturday = new Date();
var months = ['January','February','March','April','May','June','July','August','September','October','November','December'];

var stopper = true;

while(stopper){
    var x = nextSaturday.getDate();

    if(nextSaturday.getDay() == 6 && ((x > 7 && x < 15) || (x > 21 && x < 29))){
        stopper = false;
    } else {
        nextSaturday.setDate(x + 1);
    }
}

console.log("Next 2nd or 4th Saturday is " + months[nextSaturday.getMonth()] + " " + nextSaturday.getDate());

As far as I tested it, it worked, but date junk is weird.

Dan Hogan
  • 468
  • 4
  • 16