-2

I'm trying to calculate date difference using JavaScript.

My Code:

function getELECurrentdifference($this1)
  {
    var CtrDate = new Date('');
    if($this1.datepicker("getDate") != null)
    {
      var ELEcertCurrentDiff= $this1.datepicker("getDate") - CtrDate;    
      var result = ELEcertCurrentDiff / (1000 * 60 * 60 * 24) * +1;
      //$("#ELEcertDiff").text(result);
      document.getElementById("ELEcertCurrentDiff").value = result;
    }
  }

But I got a value in float.

Output:

25.39119292824074

How I can convert it to integer value like 25 only.

Any kind of help is welcome, thanks in advance.

Ganesh Aher
  • 1,118
  • 3
  • 21
  • 51

1 Answers1

1

You're looking for Math.floor. Math.floor will round down to the nearest integer any given number.

You could also use Math.trunc, which will remove any fractional digits.

Adrian
  • 8,271
  • 2
  • 26
  • 43