显示日期php之后的信息



我想在约会后显示信息。我尝试了这个,但是现在它将显示仅一天的时间更高,而不是一个月。

<?php
        $datum = date("d-m-Y");
        $begindatum = '28-04-2018';
        if ($datum >= $begindatum)
        {
          echo "test";
        }
?>

有人知道怎么了?

要比较PHP中的两个日期,您必须先将日期更改为timestamp。为此,检查strtotime()

<?php
$today = time();
$infodate = strtotime('28-04-2018');
if ($today >= $infodate) {
    echo "Information to show after 28-04-2018 goes here";
} else {
    echo "Information to show before 28-04-2018 goes here";
}
?>

或使用DateTime

<?php
$date['start'] = new DateTime();
$date['end'] = new DateTime('20-04-2018');
if ($date['start'] >= $date['end']) {
    echo "Information to show after 28-04-2018 goes here";
} else {
    echo "Information to show before 28-04-2018 goes here";
}

相关内容

最新更新