I want get a result between datetime but have been unsuccessful.
This problem has troubled me for a long time. I hope to get expert answers.
My PHP looks like this:
$fromdate = mysql_real_escape_string($_REQUEST['fromdate']);
$fromdate = date_create_from_format('d/m/Y H:i:s', $fromdate);
$fromdate = date_format($fromdate, 'Y-m-d H:i:s');
$todate= mysql_real_escape_string($_REQUEST['todate']);
$todate= date_create_from_format('d/m/Y H:i:s', $todate);
$todate= date_format($todate, 'Y-m-d H:i:s');
$qtotal = mysql_query("SELECT SUM(total) AS total FROM pos WHERE status=1 and dateline >= '".$fromdate."' AND dateline < '".$todate."'");
while ($ltotal = mysql_fetch_array($qtotal)){
$total = $ltotal['total'];
}
echo $total;
I can't get any result on the php side, but MySQL query works fine.
select
sum(total) as total
from pos
where (status =1 and dateline >= '2015-04-11 00:00:00'
and dateline < '2015-04-15 18:30:00');
dateline type is DATETIME.