Skip to content

Instantly share code, notes, and snippets.

@joe-oli
Last active July 24, 2020 07:18
Show Gist options
  • Save joe-oli/39566a7f1beba0439346a2a9b235c1f1 to your computer and use it in GitHub Desktop.
Save joe-oli/39566a7f1beba0439346a2a9b235c1f1 to your computer and use it in GitHub Desktop.
Weekend in Javascript
function isWeekend(thisDate) {
let tf = Object.prototype.toString.call(thisDate) === '[object Date]'
if (tf)
throw new Exception("input parameter is not a Date)
//.getDay() returns a integer between 0 and 6 (0 being Sunday, 6 being Saturday).
if( thisDate.getDay() == 6 || thisDate.getDay() == 0 )
return true;
else
return false;
}
/* *** USAGE *** */
let dt = new Date()
if isWeekend(dt)
alert(`${dt} is weekend')
else
alert(`${dt} is NOT weekend')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment