I need to count total no of months between the two dates in months and years if not just months either any php snippet or ether js or jquery.
I display the data from backend using php tags {{ $job->job_start_date }} job_start_date is for start date and {{ $job->job_expiry_date }}) job_expiry_date is for end date.
I get my output as in this format 13-Oct-2016. I tried this thing putting the values as hidden but couldn't get it work with parsing properly while adding new Date() to them
$(document).ready(function(){
var sDate = $("#monthStart").val();
var nDate = $("#monthEnd").val();
var sd = new Date(sDate );
var ed = new Date(nDate );
ed.setDate(ed.getDate() - sd.getDate());
alert(monthDiff(sd,ed));
});
function monthDiff(d1, d2) {
var months;
months = (d2.getFullYear() - d1.getFullYear()) * 12;
months -= d1.getMonth() + 1;
months += d2.getMonth();
return months <= 0 ? 0 : months;
}
need a easy solution in js jquery or php.