1

我从 dd-mm-yyyy 格式的 PHP 表单中得到两个日期。(说 01/06/2013 和 30/06/2013)现在我使用以下代码在上面给出的日期范围内显示日期结果,但它对我不起作用,因为存储在 DB 中的日期在 UNIX 时间戳中格式(transaction_date bigint(12))。那我应该如何显示日期结果呢?谁能帮我解决这个问题?

if($form_data['from_date']!='' && $form_data['to_date']!='') {
        $from_time  = explode("/", $form_data['from_date']);
        $to_time    = explode("/", $form_data['to_date']);

        $start_date = mktime( 0,0,0,$from_time[1],$from_time[0],$from_time[2] ) ;
        $end_date   = mktime( 23,59,59,$to_time[1],$to_time[0],$to_time[2] ) ;

        $sql  =" SELECT COUNT(*) `total count`, SUM(transaction_status = 'success') `success`, ";
        $sql .=" SUM(transaction_status = 'inprocess') `inprocess`, SUM(transaction_status = 'fail') `fail`, ";
        $sql .=" SUM(transaction_status = 'cancelled') `cancelled` FROM user_transaction ";
        $sql .=" WHERE  transaction_date >= '".$start_date."' AND transaction_date <=  '".$end_date."' GROUP BY transaction_date ";

        $this->mDb->Query( $sql);

        $queryResult = $this->mDb->FetchArray();
    }

提前致谢。

4

2 回答 2

2

用于FROM_UNIXTIME(transaction_date)获取日期类型。信息

于 2013-07-11T11:35:28.670 回答
0

在最后一行查询中进行更改并替换为以下代码:

$sql .=" WHERE  DATE_FORMAT(transaction_date,'%d-%m-%Y') >= '".$start_date."' AND DATE_FORMAT(transaction_date,'%d-%m-%Y') <=  '".$end_date."' GROUP BY FROM_UNIXTIME(transaction_date)";

这个链接对你MySQL convert datetime to Unix timestamp更有帮助。

于 2013-07-11T11:36:10.707 回答