PHP选择2个日期之间的数据

时间:2016-05-22 20:19:33

标签: php html mysql

先生,我在mysql php中尝试运算符,但结果或输出错误。

$currentdate = "05-23-2016";

$startdate = "01-01-1001";

$sql="SELECT * FROM `trial` WHERE Schedule BETWEEN '".$startdate."' AND '".$currentdate."' ";
    $result =mysql_query($sql) or die (mysql_error());
    while($row=mysql_fetch_array($result)){

            echo $row['ID']." - ".$row['Msched'].'-'.$row['Dsched'].'-'.$row['Ysched']."" ;

    }


输出 1 - 05-18-2016 4 - 04-28-2005 5 - 01-26-2020

3 个答案:

答案 0 :(得分:0)

尝试:

$sql="SELECT * FROM `trial` WHERE (Schedule BETWEEN '".$startdate."' AND '".$currentdate."') ";

答案 1 :(得分:0)

您也可以尝试:

$sql="SELECT * FROM `trial` WHERE (Schedule >= '".$startdate."' 
  AND Schedule < '".$currentdate."') ";

答案 2 :(得分:0)

试试这个:

$sql = "SELECT *FROM table WHERE schedule BETWEEN '".$startdate."' AND '".$enddate."'";