i use two datepickers to get the arrival and the departure date, counting the days for the number of nights, all is working nice, except one thing: if i take my startdate on 29.10.2011 and my enddate on the 31.10.2011 jquery counts 3 nights but there only 2 nights. Only in october, other month still working fine, hope someone could help me to figure out where my mistake is:
var oneDay = 1000*60*60*24;
var difference = Math.ceil((arrivalDate.getTime() - departureDate.getTime()) / oneDay);
The problem is that daylight saving time ends on 30th October in Europe (where, going by the German error message, you are). As a result, where there would normally be 24+24+24=72 hours between the dates, in this case, there are 24+24+24+1=73 hours between the dates. Your code therefore works out that there are 2.041666 days between the dates. Your
Math.ceilthen rounds this up to 3.The simplest solution to this in this case is probably just to replace
Math.ceilwithMath.round. When DST ends, your 2.04166 days will be rounded to 2 days. When DST starts, the 1.95834 days you’ll work out then will also be rounded to 2 days.