我知道这段代码有效:
$eventdate = new DateTime($event['date']);
$datenow = new DateTime();
if($eventdate->format('Y-m-d') < $datenow->format('Y-m-d')) ....
我需要在SQL查询中做类似的事情。
类似的东西:
SELECT * FROM MyTable WHERE `date` = `$eventdate` or Future Date
我该怎么做?
答案 0 :(得分:1)
$sql = "
SELECT *
FROM MyTable
WHERE
`date` = '{$eventdate->format('Y-m-d')}' OR
`date` >= CURDATE()
";
或
$sql = "
SELECT *
FROM MyTable
WHERE
`date` = '{$eventdate->format('Y-m-d')}' OR
`date` >= '{$datenow->format('Y-m-d')}'
";
答案 1 :(得分:0)
SELECT * FROM MyTable WHERE `date` >= `$eventdate`
答案 2 :(得分:0)
类似的东西:
SELECT
*
FROM
`table`
WHERE
`date_field` >= NOW();
这应该像在这个示例中一样:http://sqlfiddle.com/#!2/225a3/2