检查数据库中的日期是否大于当前时间

I have a PHP script to check if the date stored in the database is greater, equal or less than the current time.

  • If it is greater or equal, it echos 'greater'.
  • If it isn't greater, it echoes 'not'

My issue is that even if the time in the database is not greater or equal to the current time, it echos 'greater' (when it's supposed to echo 'not').

Date stored in the database:

enter image description here

date_default_timezone_set('Europe/London');
$time_stamp = date('Y-m-d H:i:s');

$stmt = $con->prepare("SELECT * FROM table");
$stmt->execute();

$row = $stmt->fetch();
if($row['BannedUntil'] <= $time_stamp) {
echo 'Greater';
}else{
echo 'not';
}

Use MySQL Date and Time Functions DATEDIFF

date_default_timezone_set('Europe/London');
$time_stamp = date('Y-m-d H:i:s');

$stmt = $con->prepare("SELECT DATEDIFF(`BannedUntil`,NOW()) AS `daysUntil` FROM table");
$stmt->execute();

$row = $stmt->fetch();
if($row['daysUntil'] >= 0) {
echo 'Greater'; // banned
}else{
echo 'not'; // not banned
}