1

Here is my code.

var today = new Date();
var reqDate = new Date(today.getFullYear(),today.getMonth()-3, today.getDate());
var day = today-reqDate;

I want the 'day' should be something around 90; but it gives as some long integer.

Vel Murugan S
  • 580
  • 3
  • 12
  • 31
  • 1
    There are entire Stack Overflow threads devoted to this question. Here are some of them: 1) http://stackoverflow.com/questions/542938/how-do-i-get-the-number-of-days-between-two-dates-in-javascript 2) http://stackoverflow.com/questions/3224834/get-difference-between-2-dates-in-javascript 3) http://stackoverflow.com/questions/41948/how-do-i-get-the-difference-between-two-dates-in-javascript –  Jul 16 '13 at 14:07

2 Answers2

3

The long integer is the number of milliseconds since midnight Jan 1, 1970. So in order to get the number of days you need to divide it. Code below:

var days = day/(1000*60*60*24);
Jnatalzia
  • 1,687
  • 8
  • 14
2

You have got value in day variable as milliseconds, so divide it by 1000*60*60*24 to get day count.

Another thing, it will be a decimal value.

So you have to discard fraction value using floor function.

var days = Math.floor(day/(1000*60*60*24));
MD SHAHIDUL ISLAM
  • 14,325
  • 6
  • 82
  • 89