0

I am having a bit of trouble writing a mysqli query that queries between dates.

The column in my mysql database is a datetime column.

The query I have written in php looks like this

$sessions = mysqli_query($db,"SELECT s.idSession, s.idUser, 
    FROM rempad.Session AS s WHERE s.idUser = 12 AND s.start BETWEEN '2013-04-28' AND '2013-05-28'");

I have tried escaping the dates like \'2013-04-28\'

I have also tried casting as datetime like: DATETIME(s.start) BETWEEN DATETIME('2013-04-28') AND ...

But that doesn't work.

I have tested the SQL syntax in Mysql workbench so I know that the query returns values, but I can't seem to get it right in php.

Any ideas? I can't find any examples online.

Thanks in advance L

4

1 回答 1

1

我试过了,它的工作原理是:

query($db,"SELECT s.idSession, s.idUser
    FROM rempad.Session s WHERE s.idUser = 12 AND s.start BETWEEN '2013-04-28' AND '2013-05-28'");

删除了表名后的逗号和“as”。

于 2013-08-31T13:58:23.453 回答