if entering date in first text box need duration in second textbox taking differece current date, somting working fine dd/mm/yyyy format,but need enter date in mm/dd/yyyy format. working code here please me
<input type="text" name"mydate" id="mydate" placeholder="mm/dd/yyyy"> <input type="text" name="duration" id="duration"> <script> function getyearfn() { = $("#mydate").val().split("/"); var fromdate = new date(from[2], (from[1]-1), from[0]); var today = new date(); var year1 = fromdate.getfullyear(); var year2 = today.getfullyear(); var yeardiff = year2 - year1; var month1 = fromdate.getmonth()+1; var month2 = today.getmonth()+1; var monthdiff = (month1 - month2)*-1; $('#duration').val(yeardiff +" " +"years"+" "+monthdiff*-1 +""+"months" ) } </script>
you have interchange parameters in date creation.
instead of
var fromdate = new date(from[2], (from[1]-1), from[0]); use
var fromdate = new date(from[2], (from[0]-1), from[1]);
Comments
Post a Comment