PHP strtotime returns whole year instead of a single day -
PHP strtotime returns whole year instead of a single day -
i using php round
, abs
, strtotime
calculate difference between 2 dates.
the calculation works until select $_session['b_checkout']
new year. i.e. if b_checkin
dec 30 , b_checkout
dec 31, returns right $no_nights
1 day.
$_session['b_checkin']
, $_session['b_checkout']
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 outputs (echo $no_nights
) 363 days instead of 1 day. problem?
remove commas , see works!
$b_checkin = "wednesday 31 dec 2014"; $b_checkout = "thursday 1 jan 2015"; $no_nights = round(abs(strtotime($b_checkout) - strtotime($b_checkin))/(60*60*24)); echo $no_nights;
when php can't interpret year correctly, uses current year parsing. thats how getting 363 days result.
php strtotime
Comments
Post a Comment