我想从php中的数据库中获取两个日期之间的所有记录。日期格式为dd / mm / yyyy hh:mm:ss。例子06 / Dec / 2016 05:56:15
我使用以下代码
$Sdate=date_create($_GET['sdate']);
$start=date_format($Sdate,"d/M/Y H:i:s");
$Edate=date_create($_GET['edate']);
$end=date_format($Edate,"d/M/Y H:i:s");
$sql = "SELECT * FROM `payments` WHERE `customerid` = '".$_SESSION['id']."' AND dateandtime BETWEEN ('".$start."', '".$end."') ORDER BY id DESC";
但这不起作用
提前感谢你帮助我
答案 0 :(得分:0)
试试这个:
$Sdate = date('Y-m-d H:i:s', strtotime($_GET['sdate']);
$Edate = date('Y-m-d H:i:s', strtotime($_GET['edate']);
$sql = "SELECT * FROM `payments`
WHERE `customerid` = '".$_SESSION['id']."'
AND dateandtime BETWEEN '$Sdate' AND '$Edate'
ORDER BY id DESC";
正确的语法是:
dateField BETWEEN dateFieldLow AND dateFieldHigh