dongyan7876 2015-04-15 10:45
浏览 73

无法在日期时间与2个给定日期之间获得结果

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.

  • 写回答

1条回答 默认 最新

  • duanhan5388 2015-04-17 13:11
    关注

    Thank you for trying to help, I had solve my problem by this way...
    ;I'm really confused why this can be used =.=

    $strtodate= strtotime($todate);
    $strfromdate= strtotime($fromdate);
    
    $fromdate = "".date('Y',$strfromdate)."-".date('m',$strfromdate)."-".date('d',$strfromdate)." ".date('H',$strfromdate).":".date('i',$strfromdate).":".date('s',$strfromdate)."";
    $todate = "".date('Y',$strtodate)."-".date('m',$strtodate)."-".date('d',$strtodate)." ".date('H',$strtodate).":".date('i',$strtodate).":".date('s',$strtodate)."";
    
    $qtotal = mysql_query("SELECT SUM(total) AS total FROM pos WHERE (status=1 AND dateline >= '$fromdate' AND dateline < '$todate')");
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?