简体   繁体   中英

PDO: difference between two dates (php)

I have a table of messages. I am trying to only return rows in which the datetime_read is within the last 3 days. So only messages that have been read within the past 3 days. Here is my query as it stands:

$q = 'SELECT * FROM message ORDER BY datetime_read DESC
            WHERE datetime_read...';

I am totally new to PDO and relatively new to MySQL also. Any help much appreciated. Thanks.

SELECT 
    * 
FROM 
    message
WHERE
    datetime_read >= DATE_ADD(CURDATE(), INTERVAL -3 DAY)
ORDER BY 
    datetime_read DESC;

Detail information about date/time in MySQL


Updated

  1. Note: Removed semicolon before ORDER BY (thanks to @Sai-Raja)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM