0

我希望用户可以在个人资料页面上看到他们昨天上传的照片。

我这个对吗?

SELECT * FROM pictures WHERE userid = '$userid' AND DATE(pictureuploadeddate) = DATE_SUB(CURDATE(), INTERVAL 25 HOUR) ORDER BY uploaded DESC

但仍然无法正常工作。谢谢您的帮助。

4

3 回答 3

1

尝试这个,

DATE(pictureuploadeddate) = CURDATE() - INTERVAL 1 DAY

利用索引,

pictureuploadeddate >= CURDATE() - INTERVAL 1 DAY AND pictureuploadeddate < CURDATE()
于 2013-04-17T16:28:46.557 回答
1

采取以下条件应该是可以的。

DATE_FORMAT(DATE(pictureuploadeddate), '%m-%d-%Y') = DATE_FORMAT(DATE_SUB(CURDATE(), INTERVAL 1 DAY), '%m-%d-%Y')
于 2013-04-17T16:31:57.600 回答
1

你为什么使用DATE(pictureuploadeddate)不是pictureuploadeddate日期格式列?

我下面的解决方案假设“pictureuploadeddate”是一个日期类型的列。您可以简单地进行如下比较:

SELECT * FROM pictures WHERE userid = '$userid' AND pictureuploadeddate = ADDDATE(CURDATE(), -1) ORDER BY uploaded DESC

ADDDATE(CURDATE(), -1)从今天减去 1 天返回昨天的日期。

于 2013-04-17T16:37:28.100 回答