Created
March 17, 2022 09:09
-
-
Save vin-the-dev/147f72e5d41bffba08cd816716f53486 to your computer and use it in GitHub Desktop.
Find Next Day
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://jsfiddle.net/vinbhai4u/rvw8h0k1/