I have a simple form which calculate the difference between two dates entered via two form fields named as “From” and “To” resp. When I entered dates through these two fields , the difference between two date should calculate in dayes in third field which is total days .
This is the logic I am using to calculate it but somehow its going wrong somewhere I am unable to figure out.
function Diff(){
var fDate = $('#From').val(),
tDate = $('#To').val(),
from, to, druation;
from = moment(fDate, 'YYYY-MM-DD');
to = moment(tDate, 'YYYY-MM-DD');
/* using diff */
duration = to.diff(from, 'days');
/* show the result */
$('#result').val(duration+1);
}
I am getting date in format like this “18-Mar - 2019” but I want to convert it into format like this “2019-03-18” How should I do this ?
Where am I going wrong ?