JGeer
JGeer

Reputation: 1852

jQuery hide if date is

We use the following jQuery code to display a specific block, based on the time of the day.

We want to extend this and check if the day is not 25/12 or 26/12. If it is 25/12 or 26/12 than it should also skip the code and show the else phrase.

How can we extend this?

CODE:

service("08:30:00", "17:30:00");

function service(start_time, end_time) {
    var dt = new Date();
    var stt = new Date((dt.getMonth() + 1) + "/" + dt.getDate() + "/" + dt.getFullYear() + " " + start_time);
    stt = stt.getTime();
    var endt = new Date((dt.getMonth() + 1) + "/" + dt.getDate() + "/" + dt.getFullYear() + " " + end_time);
    endt = endt.getTime();
    var time = dt.getTime();
    
    if (time > stt && time < endt) {
        $(".contact-row-open").show().removeClass("hidden");
        $(".contact-row-closed").hide().addClass("hidden");
    } else {
        $(".contact-row-open").hide().addClass("hidden");
        $(".contact-row-closed").show().removeClass("hidden");
    }
}

Upvotes: 0

Views: 158

Answers (1)

john Smith
john Smith

Reputation: 17906

you could just format month and day and check if its one of your dates and if yes return

function service(start_time, end_time) {
  var dt = new Date();
  var mm_dd = (dt.getMonth()+1)+'/'+dt.getDate();
  if(mm_dd == '12/25' || mm_dd == '12/26'){
      return false;
  }
  ....

Upvotes: 1

Related Questions