0

I am trying to add 3 years to a date that I have extracted from a cell on a Google sheet. My coded currently looks like this:

var courseDate = values[row][col];

var courseDay = courseDate.getMonth();
var courseMonth = courseDate.getMonth();
var courseYear = courseDate.getYear();

var renewalDate = new Date(courseYear + 3, courseMonth, courseDay);
Rubén
  • 34,714
  • 9
  • 70
  • 166
Sarah Rushworth
  • 813
  • 3
  • 9
  • 16
  • 2
    [Check out the **MDN** documentation for Javascript's **Date** class](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date). The methods/functions you need are documented in that link. – TheAddonDepot Feb 01 '19 at 14:55
  • You have taken `getMonth()` instead of `getDate()` in courseDay calculation. – Александр Ермолин Feb 01 '19 at 17:10
  • 1
    Possible duplicate of [Add year to todays date](https://stackoverflow.com/questions/33070428/add-year-to-todays-date) – Rubén Feb 02 '19 at 00:23
  • Thanks for all the answers. This now works - a combination of using getDate() and correcting my error using getMonth() twice. var courseDate = values[row][col]; var courseDay = courseDate.getDate(); var courseMonth = courseDate.getMonth(); var courseYear = courseDate.getFullYear(); var renewalDate = new Date(courseYear + 3, courseMonth, courseDay); – Sarah Rushworth Feb 05 '19 at 10:12

1 Answers1

0
var d = new Date();
var year = d.getFullYear();
var month = d.getMonth();
var day = d.getDate();
var c = new Date(year + 3, month, day)
turtlepower
  • 708
  • 1
  • 7
  • 18