0

我正在尝试计算两个日期之间的天数

日期格式为 dd/mm/yy

日期是可变的:

$getarrival   = $_GET["arrival"];
$getdeparture = $_GET["departure"];

我试过了,但是当你更改日期格式时它不起作用。

$start = strtotime('2010-01-25');
$end   = strtotime('2010-02-20');

$days_between = ceil(abs($end - $start) / 86400);
4

1 回答 1

0

由于我的日期格式是 dd/mm/yyyy 我将日期格式更改为 yyyy/mm/dd 并将其传递给一个新变量

list($arrivalday, $arrivalmonth, $arrivalyear) =explode("/",$getarrival);
list($departureday, $departuremonth, $departureyear) =explode("/",$getdeparture);
$newarrival = ($arrivalyear.'/'.$arrivalmonth.'/'.$arrivalday);
$newdeparture = ($departureyear.'/'.$departuremonth.'/'.$departureday);
$start = strtotime($newarrival);
$end = strtotime($newdeparture);
$totaldays = ceil(abs($end - $start) / 86400);
于 2013-02-18T21:12:24.953 回答