我尝试过研究,但无法弄明白。我的SQL表有一个类型为“date”的列,它将数据结构化为YYYY-MM-DD。如何执行SQL查询以在两个日期之间进行搜索?
如果我将开始 - 结束更改为1 - 999999999,那么它会显示我的所有数据,因此我知道我的查询正在运行。我无法理解我的日期值。
<?php
$start = '2015-01-01'
$end = '2015-12-31'
$query = "SELECT * FROM table WHERE (Week BETWEEN $start AND $end)";
?>
答案 0 :(得分:1)
尝试改变,
$query = "SELECT * FROM table WHERE (Week BETWEEN $start AND $end)";
到
$query = "SELECT * FROM table WHERE Week BETWEEN '$start' AND '$end'";
字段$ start和$ end应为日期类型
答案 1 :(得分:0)
你可以这样做
$start = '2015-01-01';
$end = '2015-12-31';
$query= "SELECT * FROM table WHERE Week
BETWEEN '$start' AND '$end'";
OR
$query= "SELECT * FROM table WHERE Week
>= '$start' AND Week <= '$end'";