我想回想一下变量和现在之间剩下多少天。这是代码
$now = date('Y-m-d');
$daysleft= strtotime($starttheproject -$now);
echo
"Now =".$now.
"<br> Starttheproject =".$starttheproject.
"<br> Daysleft =".$daysleft;
回音结果:
问题: 如何计算天数,以便结果将是&#39; 5&#39; 我一直在玩这样的代码,没有运气:
$daysleft= date('Y-m-d', strtotime($starttheproject -$now));
答案 0 :(得分:0)
试试这个:
$date = new DateTime('2014-03-10');
$finish = new DateTime();
$difference = $date->diff($finish);
$difference =$difference->format('%R%a');
if ($difference > 10) { //if the post is over 10 days old
echo 'Renew now';
}else{
echo 'Renew in '.$difference.' days</font>';
}