我正在尝试创建一个查询,它只会显示低于发布日期的“文章”。例如,我可能有一篇文章的发布日期是明天下午,这是我做的查询,但似乎没有正常工作:
SELECT a.id, CASE WHEN a.created_by_alias > ' ' THEN a.created_by_alias ELSE ua.name END AS author
FROM #__content AS a
LEFT JOIN #__users AS ua ON ua.id = a.created_by
LEFT JOIN #__categories AS c ON c.id = a.catid
WHERE a.state='1'
AND c.id!=1618
AND a.publish_up >= NOW()
AND a.title LIKE '%Europa no es una broma%'
publish_up日期返回如下:2013-12-19 20:55:00和今天的日期将是now()以同样的方式返回:2013-12-18 09:31:30(两种格式相同)。
我想要的只是那些低于今天的文章。
提前感谢您的帮助!
答案 0 :(得分:1)
试试这个
SELECT a.id, CASE WHEN a.created_by_alias > ' ' THEN a.created_by_alias ELSE ua.name END AS author
FROM #__content AS a
LEFT JOIN #__users AS ua ON ua.id = a.created_by
LEFT JOIN #__categories AS c ON c.id = a.catid
WHERE a.state='1'
AND c.id!=1618
AND DATE(a.publish_up) < Date(NOW())
AND a.title LIKE '%Europa no es una broma%'
使用DATE()函数将值返回到日期yyyy-mm-dd