-1

My js project is working fine but I need to exclude Saturdays and Sunday in it, or even holiday. Can you please check on my code on how can I achieve this.

<p>Meet me at <span id="thedate"></span></p>

<script>
var m_names = ["January", "February", "March",
    "April", "May", "June", "July", "August", "September",
    "October", "November", "December"
];

var d_names = ["Sunday", "Monday", "Tuesday", "Wednesday",
    "Thursday", "Friday", "Saturday"
];

var myDate = new Date();
myDate.setDate(myDate.getDate() + 7);
var curr_date = myDate.getDate();
var curr_month = myDate.getMonth();
var curr_day = myDate.getDay();

document.getElementById("thedate").innerHTML = (d_names[curr_day] 
    + "," + m_names[curr_month] + " " + curr_date);
</script>
isherwood
  • 58,414
  • 16
  • 114
  • 157
  • 2
    Possible duplicate of [Checking if date belongs to array of dates](https://stackoverflow.com/questions/17067296/checking-if-date-belongs-to-array-of-dates) for holidays. For weekends, [Determine if a date is a Saturday or a Sunday using JavaScript](https://stackoverflow.com/q/1181219/215552). – Heretic Monkey Apr 26 '19 at 13:22
  • I think I'd just check the current day and then add 1 more for Sunday and 2 for Saturday where you're currently adding 7. Holidays are a whole 'nother bag of worms. – isherwood Apr 26 '19 at 13:26

1 Answers1

0

You could easily find out if the day is not between monday - friday by:

// Sunday - Saturday : 0 - 6
if (curr_day < 1 || curr_day > 5) {
  // do something, maybe set it to monday?
  curr_day = 1
}
Joakim Adrup
  • 52
  • 1
  • 5