Created
January 23, 2019 19:53
-
-
Save erickhaendel/d54e2bf9d56cb7b0554a1485f5123137 to your computer and use it in GitHub Desktop.
Diferença entre datas em dias - Excluindo dias da semana
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
// Dia inicial | |
var start = new Date("2018-01-01"); | |
// Dia final | |
var finish = new Date("2018-02-01"); | |
// Adicionar tempo em milisegundos - 1 dia | |
var dayMilliseconds = 1000 * 60 * 60 * 24; | |
var diff = 0; | |
while (start.getTime() <= finish.getTime()) { | |
var day = start.getDay(); | |
// Dias da semana começando em 0 - Domingo e termina em 6 - Sabado | |
if ([1,2,3,4,5].indexOf(day)) { | |
diff++; | |
} | |
start = new Date(+start + dayMilliseconds); | |
} | |
console.log(diff); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment