I need to find the difference in days between two dates, which I have as follows:
// el formato de estas es (yyyy-mm-dd)
// Corresponden al 12 de julio del 2016 hasta el 1 de agosto del 2016
var fechaInicio = '2016-07-12';
var fechaFin = '2016-08-1';
If I try to subtract them as I have them there, the result is NaN
. How could I solve it?
You can get the milliseconds between the two dates and convert it to days:
Simple solution, for javascript date manipulation use moment.js
The method
diff
allows you to find the difference in any unit and the syntax isTo calculate the same but in hours
You get the difference in milliseconds and convert it to days.
This option only works if the date format is yy-mm-dd, if it comes in dd-mm-yy format, the date would have to be set
Yes with Moment.js you can do it