在PHP之后显示信息

时间:2018-04-29 13:32:03

标签: php date

我想在约会后显示信息。我尝试过这个,但是现在它只会显示当天更高,而不是月份。

index    S_1 S_2 S_3 S_4
 0        1    0   0   1
 1        1    1  Nan Nan

有人知道什么是错的?

1 个答案:

答案 0 :(得分:2)

要在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";
}