我正在尝试在两个日期之间获取数据,日期在mysql中存储为DATETIME
并显示为2016-04-02 04:55:03
获取日期我使用bootstrap datetimepicker和输入表单如下
<div class="input-group date" id="datetimepicker1">
<input type="text" class="form-control" id="checkin" name="from_date" data-date-format="dd/mm/yyyy" placeholder="Select Start Date">
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
</div>
<div class="gap-small"></div>
<div class="input-group date">
<input type="text" class="form-control datechange" id="checkout" name="to_date" data-date-format="dd/mm/yyyy" placeholder="Select End Date">
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
</div>
我正在使用AJAX将这些值发送给PHP。
在结果页面中:
var_dump($_POST)
结果:
array(3) { ["from_date"]=> string(10) "30/03/2016" ["to_date"]=> string(10) "05/04/2016" ["search_place"]=> array(1) { [0]=> string(0) "" } }
我在from_date
和to_date
现在,当我试图在之间和之后的日期之间进行检索时,我的sql语句
$sql="SELECT * FROM mytable WHERE evedate BETWEEN '" . $from_date . "' AND '" . $to_date . "'";
答案 0 :(得分:2)
$sql="SELECT * FROM mytable WHERE evedate BETWEEN concat(str_to_date('".$from_date."','%d/%m/%Y')) AND concat(str_to_date('".$to_date."','%d/%m/%Y')
正在运作
答案 1 :(得分:0)
您可以转换日期DATE_FORMAT
$sql="SELECT * FROM mytable WHERE DATE_FORMAT(evedate, '%m/%d/%Y') BETWEEN '" . $from_date . "' AND '" . $to_date . "'";