Issue in javascript date format?

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 ?

Hi @xcfx2888, I’m not sure what you mean… the difference in days between the 2 dates will be a number not a date, how would you want to apply a certain date format to that?

hey thanks for the reply , but I have fixed the issue and its working fine now

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.