Skip to content

Instantly share code, notes, and snippets.

@vin-the-dev
Created March 17, 2022 09:09
Show Gist options
  • Save vin-the-dev/147f72e5d41bffba08cd816716f53486 to your computer and use it in GitHub Desktop.
Save vin-the-dev/147f72e5d41bffba08cd816716f53486 to your computer and use it in GitHub Desktop.
Find Next Day
function getDay(day) {
let searchDay = -1
switch (day.toLowerCase()) {
case 'sunday':
searchDay = 0
break;
case 'monday':
searchDay = 1
break;
case 'tuesday':
searchDay = 2
break;
case 'wednesday':
searchDay = 3
break;
case 'thursday':
searchDay = 4
break;
case 'friday':
searchDay = 5
break;
case 'saturday':
searchDay = 6
break;
default:
break;
}
let d = new Date();
Date.prototype.addDays = function(days) {
var date = new Date(this.valueOf());
date.setDate(date.getDate() + days);
return date;
}
for (let index = 1; index < 8; index++) {
d = d.addDays(1)
if (d.getDay() == searchDay) {
return d
}
}
}
console.log(getDay('Monday'))
@vin-the-dev
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment