Find Out The Previous Year Date From Current Date In Javascript
I need to find out the previous year date from current date and then set as minDate in jQuery UIdatepicker in javascript My date formaqt is dd-mm-yy Ie current date is 25-07-201
Solution 1:
You need to use getFullYear()
and then generate new Date
var d = new Date(2012, 7, 25);
d.setFullYear(d.getFullYear() - 1);
Solution 2:
Try this
var d = new Date();
var pastYear = d.getFullYear() - 1;
d.setFullYear(pastYear);
console.log(d);
Solution 3:
this solution will help.
new Date(new Date().setFullYear(new Date().getFullYear() - 1));
Solution 4:
Use this :
var date = new Date();
var intYear = date.getFullYear() - 1;
Solution 5:
Datepicker allows you to put a number as the minDate
option, and it uses that as an offset from the current date. So you can write:
minDate: -365
to specify 1 year ago. This doesn't take leap years into account, though.
Post a Comment for "Find Out The Previous Year Date From Current Date In Javascript"