从DATETIME列MySQL / PHP中检索时间间隔的数据

时间:2010-09-28 02:04:54

标签: php mysql

我从数据库中提取信息并且我的查询工作正常,除了我只想从特定日期范围中选择conent。每行都有一个字段,其创建日期存储为DATETIME字段。什么是基本语法?

4 个答案:

答案 0 :(得分:2)

SELECT fields
  FROM table
 WHERE date BETWEEN '$startDate' AND '$endDate'

MySQL中的日期为YYYY-MM-DD格式,因此实际查询如下:

SELECT fields
  FROM table
 WHERE date BETWEEN '2010-10-01' AND '2010-09-25'

答案 1 :(得分:1)

WHERE `date_field` BETWEEN '2010-09-21 12:13:14' AND '2010-09-28 12:13:14'

答案 2 :(得分:1)

这是链接

http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#operator_between

select * from table where datetime between DATE1 and DATE2

答案 3 :(得分:1)

SELECT * FROM table
WHERE DateTime
BETWEEN time1 AND time2