Set date for 7 days / one week ago

2

I would like to get today's date, and subtract it 7 days. Remember that if we are on day 2 for example, you should subtract 1 from the month. The same applies to the year.

Unfortunately, I only found examples that fit for a specific day, and did not subtract a number of days.

    
asked by anonymous 23.05.2016 / 20:34

1 answer

4

Get date from a week ago / month / year ago:

var uma_semana = new Date();
uma_semana.setDate(uma_semana.getDate() - 7);

var um_mes = new Date();
um_mes.setMonth(um_mes.getMonth() - 1);

var um_ano = new Date();
um_ano.setFullYear(um_ano.getFullYear() - 1);

console.log(uma_semana);
console.log(um_mes);
console.log(um_ano);
    
23.05.2016 / 20:38