Calculate date with JavaScript or otherwise, even in excel? [closed]

2

How to arrive at an end date from a start date multiplying by N weeks, not taking into account the last week of the year. I can even calculate the dates, but I can not deduct the last week.

    
asked by anonymous 13.06.2016 / 02:34

2 answers

2

Tip using JavaScript:

function futuro(dataInicial, semanas) {
    var data = new Date(dataInicial); // para evitar mudar o objeto original
    var ano = data.getFullYear(); // saber o ano em que está
    var intervalo = semanas * 7 * 86400000; // calcular os milisegundos de diferença porque o JavaScript trabalha com milisegundos
    data.setTime(data.getTime() + intervalo); // aplicar o intervalo à data
    if (data.getFullYear() != ano) data.setTime(data.getTime() - 7 * 86400000); // tirar uma semana, caso o ano mude
    return data;
}

var hoje = new Date();
var dezembro = new Date(2016, 11, 1);

console.log(futuro(hoje, 2)); // dá Mon Jun 27 2016 06:55:25 GMT+0100 (W. Europe Standard Time)
console.log(futuro(dezembro, 6)); // dá Thu Jan 05 2017 00:00:00 GMT+0100 (W. Europe Standard Time)

jsFiddle: link

    
13.06.2016 / 06:58
0

If this is what you need, I did it in Excel, but since you were not specific, I considered only the days belonging to the last week of the year, not seven days until December 31 inclusive.

Thefinaltwocellsmustbeformattedfor"date".

In the case of the final formula, we calculate the difference between the dates of the last week of the year and add one, to get the number of days correctly to be discounted.

If you consider the last week different than what I did, just adjust the formula.

    
13.06.2016 / 03:45