javascript date minus 1 year code example

Example 1: javascript today minus 1 day

var d = new Date();
 d.setDate(d.getDate()-1);

Example 2: add 1 year to current date javascript

// [SOLVED]  var date  = new Date(year + 1, month, day);

$('#membership_start').on('dp.change', function(e){
   console.log(e.date);

   var year  = new Date(e.date).getFullYear();
   var month = new Date(e.date).getMonth();
   var day   = new Date(e.date).getDate();
   var date  = new Date(year + 1, month, day);
   $('#membership_end').data("DateTimePicker").date(date);
 });

Example 3: js date minus 18 years

use moment.js

Example 4: get current month of year in number javascript

var today = new Date();
var month = today.getMonth(); // Returns 9
console.log(month); // Output: 9