0

I am very new to JavaScript and had a question. I have done research and I just can't figure out why the following function isn't working for me. I am trying to establish Current Date and then getting various values from that value such as Current Date minus one year, Current Date plus one year, etc.

For Current Date minus year I have the following but it's not working (I would much prefer to have a one liner for other reasons:

var currentDateMinusOneYear = new Date(new Date().setFullYear(new Date().getFullYear() - 1));
console.log(currentDateMinusOneYear);

First we should get fullYear from a new Date, decrease by 1, set that as the year of a new Date. Then we wrap the whole thing in a Date constructor.

Console just returns an empty object. Not sure why. Please advise.

alchemist95
  • 759
  • 2
  • 9
  • 26
hungryhippos
  • 617
  • 4
  • 15

0 Answers0