Número de días entre dos fechas (JS)


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function getNumeroDeNits(){
  2. var d1 = $('#datepicker1').val().split("-");
  3. var dat1 = new Date(d1[2], parseFloat(d1[1])-1, parseFloat(d1[0]));
  4. var d2 = $('#datepicker2').val().split("-");
  5. var dat2 = new Date(d2[2], parseFloat(d2[1])-1, parseFloat(d2[0]));
  6.  
  7. var fin = dat2.getTime() - dat1.getTime();
  8. var dias = Math.floor(fin / (1000 * 60 * 60 * 24))
  9.  
  10. return dias;
  11. }

URL: http://blog.oridoki.com/2009/10/08/javascript-diferencia-entre-dos-fechas/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.