1
could you help me please?
I would like to use the function below in a logic that I am creating, but I would need the function below to return to me only the last week of the month, I am not able to understand how to carry out the proper changes in it so that it works the way I want, if you can help me I appreciate.
function formataData(data) {
var diaS = data.getDay();
var diaM = data.getDate();
var mes = data.getMonth();
var ano = data.getFullYear();
switch (diaS) { //converte o numero em nome do dia
case 0:
diaS = "Domingo";
break;
case 1:
diaS = "Segunda-feira";
break;
case 2:
diaS = "Terça-feira";
break;
case 3:
diaS = "Quarta-feira";
break;
case 4:
diaS = "Quinta-feira";
break;
case 5:
diaS = "Sexta-feira";
break;
case 6:
diaS = "Sabado";
break;
}
switch (mes) { //converte o numero em nome do mês
case 0:
mes = "Janeiro";
break;
case 1:
mes = "Fevereiro";
break;
case 2:
mes = "Março";
break;
case 3:
mes = "Abril";
break;
case 4:
mes = "Maio";
break;
case 5:
mes = "Junho";
break;
case 6:
mes = "Julho";
break;
case 7:
mes = "Agosto";
break;
case 8:
mes = "Setembro";
break;
case 9:
mes = "Outubro";
break;
case 10:
mes = "Novembro";
break;
case 11:
mes = "Dezembro";
break;
}
if (diaM.toString().length == 1)
diaM = "0"+diaM;
if (mes.toString().length == 1)
mes = "0"+mes;
return diaS + ", " + diaM + "/" + mes + "/" + ano;
}
var d = new Date();
var anoC = d.getFullYear();
var mesC = d.getMonth();
var d1 = new Date (anoC, mesC, 1);
var d2 = new Date (anoC, mesC+1, 0);
console.log(formataData(d1));
console.log(formataData(d2));
What do you want? List the dates of the last week of the month from Monday to Friday?
– Marcondes
That’s right @Marcondes, I want to list only the last week of the month.
– Gabriel Paixão Justino
Take the last day of the month and see if it’s a Friday, if it’s not down one and test again. Until you find the date of that month which it is. After that you know that from that point -4 will be the dates of the last week of the month, it serves?
– Marcondes
Tell me the last week of July you’ve been waiting for.
– user60252