I am trying to display user comments from a database that are older than 2 days. This is so I can screen the comments before they appear on the site. The date is entered into the database using CURDATE()
I have tried multiple ways to get this to work, but no joy so far, here's my line of code that tries to compare the dates.
$comments = "SELECT comments, initial, surname, theDate " .
"FROM tbl " .
"WHERE comments IS NOT NULL AND " .
"theDate < (unix_timestamp(CURDATE() - interval 2 day)) " .
"ORDER BY theDate DESC";
Everything gets displayed using this method.
Try to use DATEDIFF()
MySQL function:
SELECT
comments, initial, surname, theDate
FROM
tbl
WHERE
comments IS NOT NULL
AND
DATEDIFF(NOW(), theDate) > 2
ORDER BY theDate DESC
使用:NOT CURWATE() - INTERVAL 2 DAY和CURDATE(),这应该可以让你获得超过2天的所有东西
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.