你好我写了两个日期之间计算天数的PHP代码。你能告诉我哪里弄错了吗?
$today = date("Y-m-d");
$date = "2015-03-08";
$temp = date_create($date);
$datediff = $today - $temp;
$days = floor($datediff/(60*60*24));
答案 0 :(得分:1)
您可以使用phps DateTime对象:
$today = new DateTime(); // Passing no argument defaults to today
$newYear= new DateTime('2016-01-01');
$interval = $today->diff($newYear);
$diff = $interval->format('%a');
echo $diff;
输出
5
如果您想拥有签名号码,请使用此
$diff = $interval->format('%R%a');
输出
-5
所以你知道$ newYear今天之前是 5天。