用 php 显示随时间变化的事物

Display things with time with php

我想显示特定时间段的 gitfs,当我尝试我的方法时,它只显示旧礼物。我想展示一周后的礼物。

 $midnight = strtotime("now -7 days");
    $message = '';
    $user = xxx_variable
    $stmt = $this->conn->prepare("SELECT * FROM gifts WHERE to_user = ? AND time > ? ORDER BY time DESC limit 1, 25");
    $stmt->bindValue(1, $user, PDO::PARAM_STR);
    $stmt->bindValue(2, $midnight, PDO::PARAM_STR);

试试这个..

你需要使用 "UNIX_TIMESTAMP".

UNIX_TIMESTAMP(CURRENT_DATE - 间隔 7 天) -- 7 天前

 $stmt = $this->conn->prepare("SELECT * FROM gifts WHERE to_user = ? AND time > ? ORDER BY time DESC limit 1, 25");

    to 

    $stmt = $this->conn->prepare("SELECT * FROM gifts WHERE to_user = ? AND time >= UNIX_TIMESTAMP(CURRENT_DATE - INTERVAL 7 DAY) ORDER BY time DESC limit 1, 25");

如果你想要当前日期的日期,那么试试这个。

$d=date("Y-m-d");
$midnight = date('Y-m-d', strtotime($d. ' - 7 days'))