I am currently using PHP ROUND
, ABS
, STRTOTIME
to calculate the difference between two dates.
The calculation works until you select a $_SESSION['b_checkout']
from a new year. i.e. if the b_checkin
is Dec 30 and the b_checkout
is Dec 31, this returns the correct $no_nights
as 1 day.
$_SESSION['b_checkin']
and $_SESSION['b_checkout']
are using 'D F jS Y'
date format. e.g.
$_SESSION['b_checkin'] = "Wednesday, 31 December, 2014"
$_SESSION['b_checkout'] = "Thursday, 1 January, 2015"
$no_nights = round(abs(strtotime($_SESSION['b_checkout']) - strtotime($_SESSION['b_checkin']))/(60*60*24));
Currently this outputs (echo $no_nights
) 363 days instead of 1 day. What is the problem?