I am new to php i have created a dashboard where the client has to download the data by selecting the date. And the date format which is stored in our database is "d-m-Y H:i:s" and when exporting the format is like "Y-M-D" and when changed the code to "d-m-Y" the data shows blank. So any one help me how to do it. Below is my code for exporting the data in csv format.
<?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);
}
?>