0

I know this is a simple question that how to get date different in javascript but my problem is that I store the date in database like 12-jan-2015 so I don't know how to compare with other date and get the difference in days.

I tried many different ways as possible I know but still I don't get the right solution.

The last one I tried is below:

function ddiff() {
    var txtfromdate = document.getElementById('<%=txtPeriodFrom.ClientID%>').value;
    var txttodate = document.getElementById('<%=txtPeriodTo.ClientID%>').value;
    alert(txtfromdate);
    var oneDay = 1000 * 60 * 60 * 24; //Convert into millisec
    var firstDate = $.datepicker.formatDate("dd-mm-yyyy", txtfromdate);
    var secondDate = $.datepicker.formatDate("dd-mm-yyyy", txttodate);
    alert(firstDate);          
    alert(secondDate);
    var noOfDays = Math.ceil((secondDate.getTime() - firstDate.getTime()) / oneDay);
   return noOfDays;
} 

However I don't get the last two alerts, so how can I get the difference in days?

Please help me, and thanks in advance...

Mox Shah
  • 2,967
  • 2
  • 26
  • 42
Narashi Hadiya
  • 89
  • 1
  • 11

0 Answers0