【发布时间】:2014-11-05 04:26:52
【问题描述】:
我目前正在使用 PHP ROUND 、 ABS 、 STRTOTIME 来计算两个日期之间的差异。
在您从新的一年中选择 $_SESSION['b_checkout'] 之前,该计算一直有效。即,如果 b_checkin 是 12 月 30 日,b_checkout 是 12 月 31 日,则返回正确的 $no_nights 为 1 天。
$_SESSION['b_checkin'] 和 $_SESSION['b_checkout'] 使用 'D F jS Y' 日期格式。例如
$_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));
目前这个输出 (echo $no_nights) 363 天而不是 1 天。有什么问题?
【问题讨论】:
-
您的日期不是
strtotime的有效格式 ->int strtotime ( string $time) time A date/time string. Valid formats are explained in [Date and Time Formats](http://php.net/manual/en/datetime.formats.date.php)