Add year to todays date





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







36















I am trying to add a year to todays date. I am working in a system that does not allow you to use standard JavaScript.



For instance, to get todays date I have to use:



javascript:now();


I have tried:



javascript:now(+1);


I have never seen this before, but am in need of adding one year to todays date...



Has anyone seen getting current date this way before? And if so, how could I add a year?










share|improve this question


















  • 1





    Possible duplicate of How to determine one year from now in Javascript

    – rnevius
    Oct 11 '15 at 21:46











  • This is not a duplicate. Like I said above, unable to use standard javascript methodology

    – Code
    Oct 11 '15 at 21:48






  • 2





    It might be helpful if you gave us some insight into what system this code is executed in.

    – Jon Koops
    Oct 11 '15 at 21:57


















36















I am trying to add a year to todays date. I am working in a system that does not allow you to use standard JavaScript.



For instance, to get todays date I have to use:



javascript:now();


I have tried:



javascript:now(+1);


I have never seen this before, but am in need of adding one year to todays date...



Has anyone seen getting current date this way before? And if so, how could I add a year?










share|improve this question


















  • 1





    Possible duplicate of How to determine one year from now in Javascript

    – rnevius
    Oct 11 '15 at 21:46











  • This is not a duplicate. Like I said above, unable to use standard javascript methodology

    – Code
    Oct 11 '15 at 21:48






  • 2





    It might be helpful if you gave us some insight into what system this code is executed in.

    – Jon Koops
    Oct 11 '15 at 21:57














36












36








36


3






I am trying to add a year to todays date. I am working in a system that does not allow you to use standard JavaScript.



For instance, to get todays date I have to use:



javascript:now();


I have tried:



javascript:now(+1);


I have never seen this before, but am in need of adding one year to todays date...



Has anyone seen getting current date this way before? And if so, how could I add a year?










share|improve this question














I am trying to add a year to todays date. I am working in a system that does not allow you to use standard JavaScript.



For instance, to get todays date I have to use:



javascript:now();


I have tried:



javascript:now(+1);


I have never seen this before, but am in need of adding one year to todays date...



Has anyone seen getting current date this way before? And if so, how could I add a year?







javascript date






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Oct 11 '15 at 21:44









CodeCode

5312825




5312825








  • 1





    Possible duplicate of How to determine one year from now in Javascript

    – rnevius
    Oct 11 '15 at 21:46











  • This is not a duplicate. Like I said above, unable to use standard javascript methodology

    – Code
    Oct 11 '15 at 21:48






  • 2





    It might be helpful if you gave us some insight into what system this code is executed in.

    – Jon Koops
    Oct 11 '15 at 21:57














  • 1





    Possible duplicate of How to determine one year from now in Javascript

    – rnevius
    Oct 11 '15 at 21:46











  • This is not a duplicate. Like I said above, unable to use standard javascript methodology

    – Code
    Oct 11 '15 at 21:48






  • 2





    It might be helpful if you gave us some insight into what system this code is executed in.

    – Jon Koops
    Oct 11 '15 at 21:57








1




1





Possible duplicate of How to determine one year from now in Javascript

– rnevius
Oct 11 '15 at 21:46





Possible duplicate of How to determine one year from now in Javascript

– rnevius
Oct 11 '15 at 21:46













This is not a duplicate. Like I said above, unable to use standard javascript methodology

– Code
Oct 11 '15 at 21:48





This is not a duplicate. Like I said above, unable to use standard javascript methodology

– Code
Oct 11 '15 at 21:48




2




2





It might be helpful if you gave us some insight into what system this code is executed in.

– Jon Koops
Oct 11 '15 at 21:57





It might be helpful if you gave us some insight into what system this code is executed in.

– Jon Koops
Oct 11 '15 at 21:57












9 Answers
9






active

oldest

votes


















54














You can create a new date object with todays date using the following code:



var d = new Date();
console.log(d);
// => Sun Oct 11 2015 14:46:51 GMT-0700 (PDT)


If you want to create a date a specific time, you can pass the new Date constructor arguments



var d = new Date(2014);
console.log(d)
// => Wed Dec 31 1969 16:00:02 GMT-0800 (PST)


If you want to take todays date and add a year, you can first create a date object, access the relevant properties, and then use them to create a new date object



var d = new Date();
var year = d.getFullYear();
var month = d.getMonth();
var day = d.getDate();
var c = new Date(year + 1, month, day)
// => Tue Oct 11 2016 00:00:00 GMT-0700 (PDT)


You can read more about the methods on the date object on MDN



Date Object






share|improve this answer



















  • 36





    There is no need to create two date objects. d.setFullYear(d.getFullYear() + 1) will do the job in much less code.

    – RobG
    Oct 11 '15 at 23:01








  • 2





    but you will also lose the original date

    – Jonah Williams
    Oct 11 '15 at 23:11






  • 7





    This does not work with leap year date. e.g. if you enter 29/02/2016 after adding a year it will return 29/02/2017 which is incorrect.

    – Nikhil Patel
    Feb 3 '17 at 12:21






  • 3





    @ANP no, it returns 01/03/2017, which is probably still not what was required but it definitely will not return the non-existent date 29/02/2017. Keep in mind that in JavaScript, February is 1, not 2.

    – Roman Starkov
    Mar 24 '17 at 10:26






  • 1





    @ANP You are wrong, see here.

    – Timwi
    Mar 24 '17 at 14:46



















44














Use the Date.prototype.setFullYear method to set the year to what you want it to be.



For example:



var aYearFromNow = new Date();
aYearFromNow.setFullYear(aYearFromNow.getFullYear() + 1);


There really isn't another way to work with dates in JavaScript if these methods aren't present in the environment you are working with.






share|improve this answer

































    2














    This code adds the amount of years required for a date.



    var d = new Date();
    // => Tue Oct 01 2017 00:00:00 GMT-0700 (PDT)

    var amountOfYearsRequired = 2;
    d.setFullYear(d.getFullYear() + amountOfYearsRequired);
    // => Tue Oct 01 2019 00:00:00 GMT-0700 (PDT)





    share|improve this answer

































      0














      In Angular, This is how you Calculate Date



      today = new Date();
      year = this.today.getFullYear();
      month = this.today.getMonth();
      day = this.today.getDate();
      //To go 18 years back
      yearsBack18= new Date(this.year - 18, this.month, this.day);

      //To go to same day next year
      nextYear= new Date(this.year + 1, this.month, this.day);





      share|improve this answer































        0














        In case you want to add years to specific date besides today's date using either years, or months, or days. You can do the following



        var christmas2000 = new Date(2000, 12, 25); 
        christmas2000.setFullYear(christmas2000.getFullYear() + 5); // using year: next 5 years
        christmas2000.setFullYear(christmas2000.getMonth() + 24); // using months: next 24 months
        christmas2000.setFullYear(christmas2000.getDay() + 365); // using days: next 365 months





        share|improve this answer































          0














              var d = new Date();
          var year = d.getFullYear();
          var month = d.getMonth();
          var day = d.getDate();

          var fulldate = new Date(year + 1, month, day);

          var toDate = fulldate.toISOString().slice(0, 10);

          $("#txtToDate").val(toDate);

          output : 2020-01-02





          share|improve this answer

































            0














            var date = new Date();



            var year = date.getFullYear();



            var month = date.getMonth();



            month = month + 1;



            if(month < 10){



            month = “0” + month;
            }



            var day = date.getDate();



            if(day < 10){



            day = “0” + day;
            }



            year = year + 1;



            var FullDate = year + ‘/’ + month + ‘/’ + day;






            share|improve this answer































              0














              One liner as suggested here



              How to determine one year from now in Javascript
              by JP DeVries



              new Date(new Date().setFullYear(new Date().getFullYear() + 1))


              Or you can get the number of years from somewhere in a variable:



              const nr_years = 3;
              new Date(new Date().setFullYear(new Date().getFullYear() + nr_years))





              share|improve this answer































                -1














                //This piece of code will handle the leap year addition as well.



                function updateExpiryDate(controlID, value) {
                if ( $("#ICMEffectiveDate").val() != '' &&
                $("#ICMTermYears").val() != '') {

                var effectiveDate = $("#ICMEffectiveDate").val();
                var date = new Date(effectiveDate);
                var termYears = $("#ICMTermYears").val();

                date = new Date(date.setYear(date.getFullYear() + parseInt(termYears)));
                var expiryDate = (date.getMonth() + 1) + '/' + date.getDate() + '/' + date.getFullYear();
                $('#ICMExpiryDate').val(expiryDate);
                }
                }





                share|improve this answer
























                  Your Answer






                  StackExchange.ifUsing("editor", function () {
                  StackExchange.using("externalEditor", function () {
                  StackExchange.using("snippets", function () {
                  StackExchange.snippets.init();
                  });
                  });
                  }, "code-snippets");

                  StackExchange.ready(function() {
                  var channelOptions = {
                  tags: "".split(" "),
                  id: "1"
                  };
                  initTagRenderer("".split(" "), "".split(" "), channelOptions);

                  StackExchange.using("externalEditor", function() {
                  // Have to fire editor after snippets, if snippets enabled
                  if (StackExchange.settings.snippets.snippetsEnabled) {
                  StackExchange.using("snippets", function() {
                  createEditor();
                  });
                  }
                  else {
                  createEditor();
                  }
                  });

                  function createEditor() {
                  StackExchange.prepareEditor({
                  heartbeatType: 'answer',
                  autoActivateHeartbeat: false,
                  convertImagesToLinks: true,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: 10,
                  bindNavPrevention: true,
                  postfix: "",
                  imageUploader: {
                  brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                  contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                  allowUrls: true
                  },
                  onDemand: true,
                  discardSelector: ".discard-answer"
                  ,immediatelyShowMarkdownHelp:true
                  });


                  }
                  });














                  draft saved

                  draft discarded


















                  StackExchange.ready(
                  function () {
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f33070428%2fadd-year-to-todays-date%23new-answer', 'question_page');
                  }
                  );

                  Post as a guest















                  Required, but never shown

























                  9 Answers
                  9






                  active

                  oldest

                  votes








                  9 Answers
                  9






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  54














                  You can create a new date object with todays date using the following code:



                  var d = new Date();
                  console.log(d);
                  // => Sun Oct 11 2015 14:46:51 GMT-0700 (PDT)


                  If you want to create a date a specific time, you can pass the new Date constructor arguments



                  var d = new Date(2014);
                  console.log(d)
                  // => Wed Dec 31 1969 16:00:02 GMT-0800 (PST)


                  If you want to take todays date and add a year, you can first create a date object, access the relevant properties, and then use them to create a new date object



                  var d = new Date();
                  var year = d.getFullYear();
                  var month = d.getMonth();
                  var day = d.getDate();
                  var c = new Date(year + 1, month, day)
                  // => Tue Oct 11 2016 00:00:00 GMT-0700 (PDT)


                  You can read more about the methods on the date object on MDN



                  Date Object






                  share|improve this answer



















                  • 36





                    There is no need to create two date objects. d.setFullYear(d.getFullYear() + 1) will do the job in much less code.

                    – RobG
                    Oct 11 '15 at 23:01








                  • 2





                    but you will also lose the original date

                    – Jonah Williams
                    Oct 11 '15 at 23:11






                  • 7





                    This does not work with leap year date. e.g. if you enter 29/02/2016 after adding a year it will return 29/02/2017 which is incorrect.

                    – Nikhil Patel
                    Feb 3 '17 at 12:21






                  • 3





                    @ANP no, it returns 01/03/2017, which is probably still not what was required but it definitely will not return the non-existent date 29/02/2017. Keep in mind that in JavaScript, February is 1, not 2.

                    – Roman Starkov
                    Mar 24 '17 at 10:26






                  • 1





                    @ANP You are wrong, see here.

                    – Timwi
                    Mar 24 '17 at 14:46
















                  54














                  You can create a new date object with todays date using the following code:



                  var d = new Date();
                  console.log(d);
                  // => Sun Oct 11 2015 14:46:51 GMT-0700 (PDT)


                  If you want to create a date a specific time, you can pass the new Date constructor arguments



                  var d = new Date(2014);
                  console.log(d)
                  // => Wed Dec 31 1969 16:00:02 GMT-0800 (PST)


                  If you want to take todays date and add a year, you can first create a date object, access the relevant properties, and then use them to create a new date object



                  var d = new Date();
                  var year = d.getFullYear();
                  var month = d.getMonth();
                  var day = d.getDate();
                  var c = new Date(year + 1, month, day)
                  // => Tue Oct 11 2016 00:00:00 GMT-0700 (PDT)


                  You can read more about the methods on the date object on MDN



                  Date Object






                  share|improve this answer



















                  • 36





                    There is no need to create two date objects. d.setFullYear(d.getFullYear() + 1) will do the job in much less code.

                    – RobG
                    Oct 11 '15 at 23:01








                  • 2





                    but you will also lose the original date

                    – Jonah Williams
                    Oct 11 '15 at 23:11






                  • 7





                    This does not work with leap year date. e.g. if you enter 29/02/2016 after adding a year it will return 29/02/2017 which is incorrect.

                    – Nikhil Patel
                    Feb 3 '17 at 12:21






                  • 3





                    @ANP no, it returns 01/03/2017, which is probably still not what was required but it definitely will not return the non-existent date 29/02/2017. Keep in mind that in JavaScript, February is 1, not 2.

                    – Roman Starkov
                    Mar 24 '17 at 10:26






                  • 1





                    @ANP You are wrong, see here.

                    – Timwi
                    Mar 24 '17 at 14:46














                  54












                  54








                  54







                  You can create a new date object with todays date using the following code:



                  var d = new Date();
                  console.log(d);
                  // => Sun Oct 11 2015 14:46:51 GMT-0700 (PDT)


                  If you want to create a date a specific time, you can pass the new Date constructor arguments



                  var d = new Date(2014);
                  console.log(d)
                  // => Wed Dec 31 1969 16:00:02 GMT-0800 (PST)


                  If you want to take todays date and add a year, you can first create a date object, access the relevant properties, and then use them to create a new date object



                  var d = new Date();
                  var year = d.getFullYear();
                  var month = d.getMonth();
                  var day = d.getDate();
                  var c = new Date(year + 1, month, day)
                  // => Tue Oct 11 2016 00:00:00 GMT-0700 (PDT)


                  You can read more about the methods on the date object on MDN



                  Date Object






                  share|improve this answer













                  You can create a new date object with todays date using the following code:



                  var d = new Date();
                  console.log(d);
                  // => Sun Oct 11 2015 14:46:51 GMT-0700 (PDT)


                  If you want to create a date a specific time, you can pass the new Date constructor arguments



                  var d = new Date(2014);
                  console.log(d)
                  // => Wed Dec 31 1969 16:00:02 GMT-0800 (PST)


                  If you want to take todays date and add a year, you can first create a date object, access the relevant properties, and then use them to create a new date object



                  var d = new Date();
                  var year = d.getFullYear();
                  var month = d.getMonth();
                  var day = d.getDate();
                  var c = new Date(year + 1, month, day)
                  // => Tue Oct 11 2016 00:00:00 GMT-0700 (PDT)


                  You can read more about the methods on the date object on MDN



                  Date Object







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Oct 11 '15 at 21:50









                  Jonah WilliamsJonah Williams

                  5,20911728




                  5,20911728








                  • 36





                    There is no need to create two date objects. d.setFullYear(d.getFullYear() + 1) will do the job in much less code.

                    – RobG
                    Oct 11 '15 at 23:01








                  • 2





                    but you will also lose the original date

                    – Jonah Williams
                    Oct 11 '15 at 23:11






                  • 7





                    This does not work with leap year date. e.g. if you enter 29/02/2016 after adding a year it will return 29/02/2017 which is incorrect.

                    – Nikhil Patel
                    Feb 3 '17 at 12:21






                  • 3





                    @ANP no, it returns 01/03/2017, which is probably still not what was required but it definitely will not return the non-existent date 29/02/2017. Keep in mind that in JavaScript, February is 1, not 2.

                    – Roman Starkov
                    Mar 24 '17 at 10:26






                  • 1





                    @ANP You are wrong, see here.

                    – Timwi
                    Mar 24 '17 at 14:46














                  • 36





                    There is no need to create two date objects. d.setFullYear(d.getFullYear() + 1) will do the job in much less code.

                    – RobG
                    Oct 11 '15 at 23:01








                  • 2





                    but you will also lose the original date

                    – Jonah Williams
                    Oct 11 '15 at 23:11






                  • 7





                    This does not work with leap year date. e.g. if you enter 29/02/2016 after adding a year it will return 29/02/2017 which is incorrect.

                    – Nikhil Patel
                    Feb 3 '17 at 12:21






                  • 3





                    @ANP no, it returns 01/03/2017, which is probably still not what was required but it definitely will not return the non-existent date 29/02/2017. Keep in mind that in JavaScript, February is 1, not 2.

                    – Roman Starkov
                    Mar 24 '17 at 10:26






                  • 1





                    @ANP You are wrong, see here.

                    – Timwi
                    Mar 24 '17 at 14:46








                  36




                  36





                  There is no need to create two date objects. d.setFullYear(d.getFullYear() + 1) will do the job in much less code.

                  – RobG
                  Oct 11 '15 at 23:01







                  There is no need to create two date objects. d.setFullYear(d.getFullYear() + 1) will do the job in much less code.

                  – RobG
                  Oct 11 '15 at 23:01






                  2




                  2





                  but you will also lose the original date

                  – Jonah Williams
                  Oct 11 '15 at 23:11





                  but you will also lose the original date

                  – Jonah Williams
                  Oct 11 '15 at 23:11




                  7




                  7





                  This does not work with leap year date. e.g. if you enter 29/02/2016 after adding a year it will return 29/02/2017 which is incorrect.

                  – Nikhil Patel
                  Feb 3 '17 at 12:21





                  This does not work with leap year date. e.g. if you enter 29/02/2016 after adding a year it will return 29/02/2017 which is incorrect.

                  – Nikhil Patel
                  Feb 3 '17 at 12:21




                  3




                  3





                  @ANP no, it returns 01/03/2017, which is probably still not what was required but it definitely will not return the non-existent date 29/02/2017. Keep in mind that in JavaScript, February is 1, not 2.

                  – Roman Starkov
                  Mar 24 '17 at 10:26





                  @ANP no, it returns 01/03/2017, which is probably still not what was required but it definitely will not return the non-existent date 29/02/2017. Keep in mind that in JavaScript, February is 1, not 2.

                  – Roman Starkov
                  Mar 24 '17 at 10:26




                  1




                  1





                  @ANP You are wrong, see here.

                  – Timwi
                  Mar 24 '17 at 14:46





                  @ANP You are wrong, see here.

                  – Timwi
                  Mar 24 '17 at 14:46













                  44














                  Use the Date.prototype.setFullYear method to set the year to what you want it to be.



                  For example:



                  var aYearFromNow = new Date();
                  aYearFromNow.setFullYear(aYearFromNow.getFullYear() + 1);


                  There really isn't another way to work with dates in JavaScript if these methods aren't present in the environment you are working with.






                  share|improve this answer






























                    44














                    Use the Date.prototype.setFullYear method to set the year to what you want it to be.



                    For example:



                    var aYearFromNow = new Date();
                    aYearFromNow.setFullYear(aYearFromNow.getFullYear() + 1);


                    There really isn't another way to work with dates in JavaScript if these methods aren't present in the environment you are working with.






                    share|improve this answer




























                      44












                      44








                      44







                      Use the Date.prototype.setFullYear method to set the year to what you want it to be.



                      For example:



                      var aYearFromNow = new Date();
                      aYearFromNow.setFullYear(aYearFromNow.getFullYear() + 1);


                      There really isn't another way to work with dates in JavaScript if these methods aren't present in the environment you are working with.






                      share|improve this answer















                      Use the Date.prototype.setFullYear method to set the year to what you want it to be.



                      For example:



                      var aYearFromNow = new Date();
                      aYearFromNow.setFullYear(aYearFromNow.getFullYear() + 1);


                      There really isn't another way to work with dates in JavaScript if these methods aren't present in the environment you are working with.







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Mar 17 '17 at 16:57

























                      answered Oct 11 '15 at 21:51









                      Jon KoopsJon Koops

                      3,84242242




                      3,84242242























                          2














                          This code adds the amount of years required for a date.



                          var d = new Date();
                          // => Tue Oct 01 2017 00:00:00 GMT-0700 (PDT)

                          var amountOfYearsRequired = 2;
                          d.setFullYear(d.getFullYear() + amountOfYearsRequired);
                          // => Tue Oct 01 2019 00:00:00 GMT-0700 (PDT)





                          share|improve this answer






























                            2














                            This code adds the amount of years required for a date.



                            var d = new Date();
                            // => Tue Oct 01 2017 00:00:00 GMT-0700 (PDT)

                            var amountOfYearsRequired = 2;
                            d.setFullYear(d.getFullYear() + amountOfYearsRequired);
                            // => Tue Oct 01 2019 00:00:00 GMT-0700 (PDT)





                            share|improve this answer




























                              2












                              2








                              2







                              This code adds the amount of years required for a date.



                              var d = new Date();
                              // => Tue Oct 01 2017 00:00:00 GMT-0700 (PDT)

                              var amountOfYearsRequired = 2;
                              d.setFullYear(d.getFullYear() + amountOfYearsRequired);
                              // => Tue Oct 01 2019 00:00:00 GMT-0700 (PDT)





                              share|improve this answer















                              This code adds the amount of years required for a date.



                              var d = new Date();
                              // => Tue Oct 01 2017 00:00:00 GMT-0700 (PDT)

                              var amountOfYearsRequired = 2;
                              d.setFullYear(d.getFullYear() + amountOfYearsRequired);
                              // => Tue Oct 01 2019 00:00:00 GMT-0700 (PDT)






                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Nov 27 '18 at 10:07

























                              answered Sep 24 '18 at 20:29









                              Lucas VellidoLucas Vellido

                              234




                              234























                                  0














                                  In Angular, This is how you Calculate Date



                                  today = new Date();
                                  year = this.today.getFullYear();
                                  month = this.today.getMonth();
                                  day = this.today.getDate();
                                  //To go 18 years back
                                  yearsBack18= new Date(this.year - 18, this.month, this.day);

                                  //To go to same day next year
                                  nextYear= new Date(this.year + 1, this.month, this.day);





                                  share|improve this answer




























                                    0














                                    In Angular, This is how you Calculate Date



                                    today = new Date();
                                    year = this.today.getFullYear();
                                    month = this.today.getMonth();
                                    day = this.today.getDate();
                                    //To go 18 years back
                                    yearsBack18= new Date(this.year - 18, this.month, this.day);

                                    //To go to same day next year
                                    nextYear= new Date(this.year + 1, this.month, this.day);





                                    share|improve this answer


























                                      0












                                      0








                                      0







                                      In Angular, This is how you Calculate Date



                                      today = new Date();
                                      year = this.today.getFullYear();
                                      month = this.today.getMonth();
                                      day = this.today.getDate();
                                      //To go 18 years back
                                      yearsBack18= new Date(this.year - 18, this.month, this.day);

                                      //To go to same day next year
                                      nextYear= new Date(this.year + 1, this.month, this.day);





                                      share|improve this answer













                                      In Angular, This is how you Calculate Date



                                      today = new Date();
                                      year = this.today.getFullYear();
                                      month = this.today.getMonth();
                                      day = this.today.getDate();
                                      //To go 18 years back
                                      yearsBack18= new Date(this.year - 18, this.month, this.day);

                                      //To go to same day next year
                                      nextYear= new Date(this.year + 1, this.month, this.day);






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Dec 18 '18 at 12:59









                                      Agidigbi Ayodeji VictorAgidigbi Ayodeji Victor

                                      472




                                      472























                                          0














                                          In case you want to add years to specific date besides today's date using either years, or months, or days. You can do the following



                                          var christmas2000 = new Date(2000, 12, 25); 
                                          christmas2000.setFullYear(christmas2000.getFullYear() + 5); // using year: next 5 years
                                          christmas2000.setFullYear(christmas2000.getMonth() + 24); // using months: next 24 months
                                          christmas2000.setFullYear(christmas2000.getDay() + 365); // using days: next 365 months





                                          share|improve this answer




























                                            0














                                            In case you want to add years to specific date besides today's date using either years, or months, or days. You can do the following



                                            var christmas2000 = new Date(2000, 12, 25); 
                                            christmas2000.setFullYear(christmas2000.getFullYear() + 5); // using year: next 5 years
                                            christmas2000.setFullYear(christmas2000.getMonth() + 24); // using months: next 24 months
                                            christmas2000.setFullYear(christmas2000.getDay() + 365); // using days: next 365 months





                                            share|improve this answer


























                                              0












                                              0








                                              0







                                              In case you want to add years to specific date besides today's date using either years, or months, or days. You can do the following



                                              var christmas2000 = new Date(2000, 12, 25); 
                                              christmas2000.setFullYear(christmas2000.getFullYear() + 5); // using year: next 5 years
                                              christmas2000.setFullYear(christmas2000.getMonth() + 24); // using months: next 24 months
                                              christmas2000.setFullYear(christmas2000.getDay() + 365); // using days: next 365 months





                                              share|improve this answer













                                              In case you want to add years to specific date besides today's date using either years, or months, or days. You can do the following



                                              var christmas2000 = new Date(2000, 12, 25); 
                                              christmas2000.setFullYear(christmas2000.getFullYear() + 5); // using year: next 5 years
                                              christmas2000.setFullYear(christmas2000.getMonth() + 24); // using months: next 24 months
                                              christmas2000.setFullYear(christmas2000.getDay() + 365); // using days: next 365 months






                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered Dec 24 '18 at 9:54









                                              Phemelo KhethoPhemelo Khetho

                                              217




                                              217























                                                  0














                                                      var d = new Date();
                                                  var year = d.getFullYear();
                                                  var month = d.getMonth();
                                                  var day = d.getDate();

                                                  var fulldate = new Date(year + 1, month, day);

                                                  var toDate = fulldate.toISOString().slice(0, 10);

                                                  $("#txtToDate").val(toDate);

                                                  output : 2020-01-02





                                                  share|improve this answer






























                                                    0














                                                        var d = new Date();
                                                    var year = d.getFullYear();
                                                    var month = d.getMonth();
                                                    var day = d.getDate();

                                                    var fulldate = new Date(year + 1, month, day);

                                                    var toDate = fulldate.toISOString().slice(0, 10);

                                                    $("#txtToDate").val(toDate);

                                                    output : 2020-01-02





                                                    share|improve this answer




























                                                      0












                                                      0








                                                      0







                                                          var d = new Date();
                                                      var year = d.getFullYear();
                                                      var month = d.getMonth();
                                                      var day = d.getDate();

                                                      var fulldate = new Date(year + 1, month, day);

                                                      var toDate = fulldate.toISOString().slice(0, 10);

                                                      $("#txtToDate").val(toDate);

                                                      output : 2020-01-02





                                                      share|improve this answer















                                                          var d = new Date();
                                                      var year = d.getFullYear();
                                                      var month = d.getMonth();
                                                      var day = d.getDate();

                                                      var fulldate = new Date(year + 1, month, day);

                                                      var toDate = fulldate.toISOString().slice(0, 10);

                                                      $("#txtToDate").val(toDate);

                                                      output : 2020-01-02






                                                      share|improve this answer














                                                      share|improve this answer



                                                      share|improve this answer








                                                      edited Jan 3 at 2:49

























                                                      answered Jan 2 at 4:51









                                                      Md ShahriarMd Shahriar

                                                      32427




                                                      32427























                                                          0














                                                          var date = new Date();



                                                          var year = date.getFullYear();



                                                          var month = date.getMonth();



                                                          month = month + 1;



                                                          if(month < 10){



                                                          month = “0” + month;
                                                          }



                                                          var day = date.getDate();



                                                          if(day < 10){



                                                          day = “0” + day;
                                                          }



                                                          year = year + 1;



                                                          var FullDate = year + ‘/’ + month + ‘/’ + day;






                                                          share|improve this answer




























                                                            0














                                                            var date = new Date();



                                                            var year = date.getFullYear();



                                                            var month = date.getMonth();



                                                            month = month + 1;



                                                            if(month < 10){



                                                            month = “0” + month;
                                                            }



                                                            var day = date.getDate();



                                                            if(day < 10){



                                                            day = “0” + day;
                                                            }



                                                            year = year + 1;



                                                            var FullDate = year + ‘/’ + month + ‘/’ + day;






                                                            share|improve this answer


























                                                              0












                                                              0








                                                              0







                                                              var date = new Date();



                                                              var year = date.getFullYear();



                                                              var month = date.getMonth();



                                                              month = month + 1;



                                                              if(month < 10){



                                                              month = “0” + month;
                                                              }



                                                              var day = date.getDate();



                                                              if(day < 10){



                                                              day = “0” + day;
                                                              }



                                                              year = year + 1;



                                                              var FullDate = year + ‘/’ + month + ‘/’ + day;






                                                              share|improve this answer













                                                              var date = new Date();



                                                              var year = date.getFullYear();



                                                              var month = date.getMonth();



                                                              month = month + 1;



                                                              if(month < 10){



                                                              month = “0” + month;
                                                              }



                                                              var day = date.getDate();



                                                              if(day < 10){



                                                              day = “0” + day;
                                                              }



                                                              year = year + 1;



                                                              var FullDate = year + ‘/’ + month + ‘/’ + day;







                                                              share|improve this answer












                                                              share|improve this answer



                                                              share|improve this answer










                                                              answered Jan 3 at 3:02









                                                              Md ShahriarMd Shahriar

                                                              32427




                                                              32427























                                                                  0














                                                                  One liner as suggested here



                                                                  How to determine one year from now in Javascript
                                                                  by JP DeVries



                                                                  new Date(new Date().setFullYear(new Date().getFullYear() + 1))


                                                                  Or you can get the number of years from somewhere in a variable:



                                                                  const nr_years = 3;
                                                                  new Date(new Date().setFullYear(new Date().getFullYear() + nr_years))





                                                                  share|improve this answer




























                                                                    0














                                                                    One liner as suggested here



                                                                    How to determine one year from now in Javascript
                                                                    by JP DeVries



                                                                    new Date(new Date().setFullYear(new Date().getFullYear() + 1))


                                                                    Or you can get the number of years from somewhere in a variable:



                                                                    const nr_years = 3;
                                                                    new Date(new Date().setFullYear(new Date().getFullYear() + nr_years))





                                                                    share|improve this answer


























                                                                      0












                                                                      0








                                                                      0







                                                                      One liner as suggested here



                                                                      How to determine one year from now in Javascript
                                                                      by JP DeVries



                                                                      new Date(new Date().setFullYear(new Date().getFullYear() + 1))


                                                                      Or you can get the number of years from somewhere in a variable:



                                                                      const nr_years = 3;
                                                                      new Date(new Date().setFullYear(new Date().getFullYear() + nr_years))





                                                                      share|improve this answer













                                                                      One liner as suggested here



                                                                      How to determine one year from now in Javascript
                                                                      by JP DeVries



                                                                      new Date(new Date().setFullYear(new Date().getFullYear() + 1))


                                                                      Or you can get the number of years from somewhere in a variable:



                                                                      const nr_years = 3;
                                                                      new Date(new Date().setFullYear(new Date().getFullYear() + nr_years))






                                                                      share|improve this answer












                                                                      share|improve this answer



                                                                      share|improve this answer










                                                                      answered Feb 28 at 16:32









                                                                      SzekelygobeSzekelygobe

                                                                      17729




                                                                      17729























                                                                          -1














                                                                          //This piece of code will handle the leap year addition as well.



                                                                          function updateExpiryDate(controlID, value) {
                                                                          if ( $("#ICMEffectiveDate").val() != '' &&
                                                                          $("#ICMTermYears").val() != '') {

                                                                          var effectiveDate = $("#ICMEffectiveDate").val();
                                                                          var date = new Date(effectiveDate);
                                                                          var termYears = $("#ICMTermYears").val();

                                                                          date = new Date(date.setYear(date.getFullYear() + parseInt(termYears)));
                                                                          var expiryDate = (date.getMonth() + 1) + '/' + date.getDate() + '/' + date.getFullYear();
                                                                          $('#ICMExpiryDate').val(expiryDate);
                                                                          }
                                                                          }





                                                                          share|improve this answer




























                                                                            -1














                                                                            //This piece of code will handle the leap year addition as well.



                                                                            function updateExpiryDate(controlID, value) {
                                                                            if ( $("#ICMEffectiveDate").val() != '' &&
                                                                            $("#ICMTermYears").val() != '') {

                                                                            var effectiveDate = $("#ICMEffectiveDate").val();
                                                                            var date = new Date(effectiveDate);
                                                                            var termYears = $("#ICMTermYears").val();

                                                                            date = new Date(date.setYear(date.getFullYear() + parseInt(termYears)));
                                                                            var expiryDate = (date.getMonth() + 1) + '/' + date.getDate() + '/' + date.getFullYear();
                                                                            $('#ICMExpiryDate').val(expiryDate);
                                                                            }
                                                                            }





                                                                            share|improve this answer


























                                                                              -1












                                                                              -1








                                                                              -1







                                                                              //This piece of code will handle the leap year addition as well.



                                                                              function updateExpiryDate(controlID, value) {
                                                                              if ( $("#ICMEffectiveDate").val() != '' &&
                                                                              $("#ICMTermYears").val() != '') {

                                                                              var effectiveDate = $("#ICMEffectiveDate").val();
                                                                              var date = new Date(effectiveDate);
                                                                              var termYears = $("#ICMTermYears").val();

                                                                              date = new Date(date.setYear(date.getFullYear() + parseInt(termYears)));
                                                                              var expiryDate = (date.getMonth() + 1) + '/' + date.getDate() + '/' + date.getFullYear();
                                                                              $('#ICMExpiryDate').val(expiryDate);
                                                                              }
                                                                              }





                                                                              share|improve this answer













                                                                              //This piece of code will handle the leap year addition as well.



                                                                              function updateExpiryDate(controlID, value) {
                                                                              if ( $("#ICMEffectiveDate").val() != '' &&
                                                                              $("#ICMTermYears").val() != '') {

                                                                              var effectiveDate = $("#ICMEffectiveDate").val();
                                                                              var date = new Date(effectiveDate);
                                                                              var termYears = $("#ICMTermYears").val();

                                                                              date = new Date(date.setYear(date.getFullYear() + parseInt(termYears)));
                                                                              var expiryDate = (date.getMonth() + 1) + '/' + date.getDate() + '/' + date.getFullYear();
                                                                              $('#ICMExpiryDate').val(expiryDate);
                                                                              }
                                                                              }






                                                                              share|improve this answer












                                                                              share|improve this answer



                                                                              share|improve this answer










                                                                              answered Jul 19 '17 at 12:59









                                                                              Vishal GoelVishal Goel

                                                                              11




                                                                              11






























                                                                                  draft saved

                                                                                  draft discarded




















































                                                                                  Thanks for contributing an answer to Stack Overflow!


                                                                                  • Please be sure to answer the question. Provide details and share your research!

                                                                                  But avoid



                                                                                  • Asking for help, clarification, or responding to other answers.

                                                                                  • Making statements based on opinion; back them up with references or personal experience.


                                                                                  To learn more, see our tips on writing great answers.




                                                                                  draft saved


                                                                                  draft discarded














                                                                                  StackExchange.ready(
                                                                                  function () {
                                                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f33070428%2fadd-year-to-todays-date%23new-answer', 'question_page');
                                                                                  }
                                                                                  );

                                                                                  Post as a guest















                                                                                  Required, but never shown





















































                                                                                  Required, but never shown














                                                                                  Required, but never shown












                                                                                  Required, but never shown







                                                                                  Required, but never shown

































                                                                                  Required, but never shown














                                                                                  Required, but never shown












                                                                                  Required, but never shown







                                                                                  Required, but never shown







                                                                                  Popular posts from this blog

                                                                                  MongoDB - Not Authorized To Execute Command

                                                                                  How to fix TextFormField cause rebuild widget in Flutter

                                                                                  in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith