要导入Excel工作表的日期格式?

时间:2018-07-24 13:24:13

标签: php export-to-csv

我是php新手,我创建了一个仪表板,客户端必须通过选择日期来下载数据。存储在我们数据库中的日期格式为“ d-m-Y H:i:s”,导出时的格式为“ Y-M-D”,而将代码更改为“ d-m-Y”时,数据显示为空白。所以任何人都可以帮助我。下面是我以csv格式导出数据的代码。

    <?php
        include('connection.php');    
        //export csv file    
        $from= $_POST['from'].' 00:00:00';
        $to= $_POST['to'].' 23:59:59';
        $today = date("d-m-Y");
        $end = date("d-m-Y");
        $start = (isset($_POST['from'])) ? $_POST['from'] : '$today';    
        $end = (isset($_POST['to'])) ? $_POST['to'] : '$end';
        //echo $start;
        //echo $end;
        if(isset($_POST["export"])) {    
            header("Content-type: text/csv; charset=utf-8");
            header("Content-disposition: attachment; filename=data-$start-$end.csv");
            $output = fopen("php://output", "w");
            fputcsv($output, array('SL NO','Mobile','Prescription','Address','Landmark','City','Date and Time'));
            $query = "SELECT id,number,upload,address,landmark,city,entered_date FROM usedetails WHERE entered_date BETWEEN '" . $from. "' AND '" . $to. "'";
            $result = mysqli_query($conn,$query);
            while($row = mysqli_fetch_assoc($result)) {
               fputcsv($output, $row);
            }
            fclose($output);
        }    
    ?>

0 个答案:

没有答案