我已经到处搜索了,我似乎只找到了如何获取单个日期在两个“外部”日期之间的记录。
我想了解如何选择当前日期介于 startDate 字段中的值和 endDate 字段中的值之间的记录。
到目前为止我所拥有的(PHP):
$now = new DateTime();
$sql = "
SELECT content, image, imageHeight, imageWidth, link, linkDescription
FROM news
WHERE appearanceDate < $now
AND $now < termDate
ORDER BY appearanceDate DESC
";
Run Code Online (Sandbox Code Playgroud)
但它不起作用。
您可以NOW()
在mysql 中使用该功能。请注意,这假设termDate
是较晚的日期:
Select content, image, imageHeight, imageWidth, link, linkDescription
From news
Where appearanceDate < NOW()
And termDate > NOW()
Order By appearanceDate Desc;
Run Code Online (Sandbox Code Playgroud)