3
Hello, folks, I’m trying to fill an array with days from the current day until 30 days from now.
Here is a problem: if today is the 8th, in 30 days it will be 38, but I want the count to return to 1 from the maximum day of each month. To get around this, I’m trying to use the following logic:
//busca o dia de hoje e preenche o array com os dias de hoje + 30 dias
var today = new Date();
var dd = today.getDate();
var somaTrinta = dd + 30;
//vetor que possui o máximo de dias por cada mês
var diasPorMes = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
var mm = today.getMonth();
var maximoDias = diasPorMes[mm];
var i;
for(i = dd; i < somaTrinta; i++) {
if (i > maximoDias) {
i = 1;
}
horizontal.push(i);
}
However, after inserting if, the page doesn’t even load anymore. I don’t know what my mistake is, can anyone help me? Thanks
Thanks Dnick, really solved my problem.
– Gabriel Augusto