0

Does anyone know what is wrong, that this script in this case, a bad number of days in the difference in dates? The difference should be 2 days - the script shows 1 day.
If the difference is in the same month is OK.

<script type="text/javascript">

var date_from = new Date(2012, 03, 31).getTime();

var date_to = new Date(2012, 04, 02).getTime();

document.write((date_to - date_from)/(1000*60*60*24));

</script>
1
Contributor
1
Reply
2
Views
5 Years
Discussion Span
Last Post by piotrekw
1

ok problem solved!
Good code:

<script type="text/javascript">

      var mDate_od = new Date(2012, (03-1), 31).getTime();
      var mDate_do = new Date(2012, (04-1), 03).getTime();
	document.write(Math.abs(Math.round((mDate_do - mDate_od)/(1000*60*60*24))));

 </script>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.