计算php中两个日期之间的天数

时间:2013-02-18 15:11:57

标签: php

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

日期格式为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);

1 个答案:

答案 0 :(得分: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);