Trafalgar D Law Trafalgar D Law - 1 month ago 8
jQuery Question

How to determine if next 3 days has weekend?

So far this is what I have done. But the output is different for what I am expecting for except for the 3rd sample but it only display the

+1 date
not the whole date.



var datess = new Date();
var ndate = new Date(datess.getDate() + 1);
var ndate2 = datess.getDate() + 1;


document.getElementById("newdate").innerHTML = datess;
document.getElementById("newdate1").innerHTML = ndate;
document.getElementById("newdate2").innerHTML = ndate2;

<div id = "newdate">

</div>
<div id = "newdate1">

</div>
<div id = "newdate2">

</div>





What I want to achieve on this is after determining if it has a weekend it will pass into a
variable
and that variable will be use in loop.

Answer

var today = new Date();
var tomorrow = new Date(today.getTime() + 24 * 60 * 60 * 1000);
var afterTomorrow = new Date(tomorrow.getTime() + 24 * 60 * 60 * 1000);


document.getElementById("newdate").innerHTML = today;
document.getElementById("newdate1").innerHTML = tomorrow;
document.getElementById("newdate2").innerHTML = afterTomorrow;

//getDay() return day number
//0 - Sunday
//1 - Monday
//2 - Tuesday
//...
if (tomorrow.getDay() == 0) {
  console.log("Tomorrow is sunday !");
} else if (tomorrow.getDay() == 6) {
  console.log("Tomorrow is Saturday !");
}
//Do same with after tomorrow
<div id="newdate"></div>
<div id="newdate1"></div>
<div id="newdate2"></div>