0

我知道这段代码有效:

$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

我怎样才能做到这一点?

4

3 回答 3

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')}'
";
于 2013-09-27T10:38:52.823 回答
0
SELECT * FROM MyTable WHERE `date` >= `$eventdate`
于 2013-09-27T10:30:10.440 回答
0

就像是:

SELECT
  *
FROM
  `table`
WHERE
  `date_field` >= NOW();

这应该在这个例子中工作:http ://sqlfiddle.com/#!2/225a3/2

于 2013-09-27T10:42:17.373 回答