Time difference in php and javascript

There are the following field values:

date1 = 10/18/2011
time1 = 0:00
date2 = 31/18/2011
time2 = 0:00

In JavaScript, we calculate the difference of days like this:

var date1 = $('input[name=date1]').val()+' '+$('select[name=time1]').val();
var date2 = $('input[name=date2]').val()+' '+$('select[name=time2]').val();
var rent_time_1 = new Date(date1);
var rent_time_2 = new Date(date2);
var nDaysLeft = rent_time_2 > rent_time_1 ? Math.ceil((rent_time_2 - rent_time_1) / (1000 * 60 * 60 * 24)) : null;

In php we think like this:

$rent_time_1 = $IN->GBL('date1', 'POST').' '.$IN->GBL('time1', 'POST');
$rent_time_1 = strtotime($rent_time_1);
$rent_time_2 = $IN->GBL('date2', 'POST').' '.$IN->GBL('time2', 'POST');
$rent_time_2 = strtotime($rent_time_2);
$days = ($rent_time_2 - $rent_time_1) / 86400;

For JS it’s 14 days, and for php it’s 13.


Answer 1

So in JS you have ceil, but not in PHP? Here’s the difference: Math.ceil rounds up to get 14, while PHP apparently cuts off (downwards) to get 13.


Answer 2

Where does it count correctly, in php or javascript?