我试图确定日期是否在未来,使用DateTime对象,但它总是回来积极:
$opening_date = new DateTime($current_store['openingdate']);
$current_date = new DateTime();
$diff = $opening_date->diff($current_date);
echo $diff->format('%R'); // +
if($diff->format('%R') == '+' && $current_store['openingdate'] != '0000-00-00' && $current_store['openingdate'] !== NULL) {
echo '<img id="openingsoon" src="/img/misc/openingsoon.jpg" alt="OPENING SOON" />';
}
Run Code Online (Sandbox Code Playgroud)
问题是它总是积极的,所以图像显示它不应该是什么时候.
我必须做一些愚蠢的事,但它是什么,它让我疯了!