查询以返回超过6个月前的值

时间:2014-04-11 01:39:37

标签: php mysql sql datetime

这是迄今为止的代码

$result = mysqli_query($con,"SELECT * FROM users WHERE User_Last_Login> ");

user_last_login的格式为yyyy-mm-dd

1 个答案:

答案 0 :(得分:2)

SELECT * FROM users WHERE User_Last_Login < DATE_SUB(NOW(), INTERVAL 6 MONTH)

SELECT * FROM users WHERE User_Last_Login < NOW() - INTERVAL 6 MONTH

SELECT * FROM users WHERE User_Last_Login < DATE_SUB(CURDATE(), INTERVAL 6 MONTH)