Choose Your Fromdate in given textbox
input name="datepicker" id="textboxid" type="text" readonly="readonly" placeholder="Select your fromdate" onchange=""
1.your selecting date stored in one variable
var datepick = $("#textboxid").val();
//your choose date like 03/06/2015
2.you want to take day,month,year separately from the datepicker means use following format
var fromdate = from.slice(0, 2);
// like 03
var frommonth = from.slice(3, 5);
// like 06
var fromyear = from.slice(6, 10);
//like 2015
3.After getting fromdate separately we move to today date calculation.
var dateString = Date.now();
// We get date like dateString = 1439454966423
var currentTime = new Date(parseInt(dateString));
//currentTime = Thu Aug 13 2015 14:06:06 GMT+0530 (India Standard Time) {}
4.current date are stored in one variable like below
var to = currentTime.yyyymmdd();
//2015/08/13
5.you want to take day,month,year separately from the today date means use following format
var todate = to.slice(8, 10);
// You get like 13
var tomonth = to.slice(5, 7);
// You get like 08
var toyear = to.slice(0, 4);
// You get like 2015
6.oneday calculation
var oneDay = 24 * 60 * 60 * 1000;
7.you getting from date like(year,month,day) wise and todate(year,month,day) for diff calculation means use following format
var firstDate = new Date(fromyear, frommonth, fromdate);
var secondDate = new Date(toyear, tomonth, todate);
8.below script used for days calculation between firstDate and secondDate.
var diffDays = Math.round(Math.abs((firstDate.getTime() - secondDate.getTime()) / (oneDay)));
9.we are calculating year from the diffdays.
var getyear = Math.ceil(diffDays / 365);
10.To return formated datetime value you can use the following method.
Date.prototype.yyyymmdd = function () { var yyyy =this.getFullYear().toString(); var mm = (this.getMonth() +1).toString();
// getMonth() is zero-based var dd =this.getDate().toString(); return yyyy + "-" +(mm[1] ? mm : "0" +mm[0]) + "-" + (dd[1] ? dd : "0" + dd[0]); // padding };