im trying to sort my data table by the 3rd column(Date column) however it only seems to sort it by the 1st number in the date column as shown in picture below how can I get it so that it sorts by date rather than numeric?
echo "<table>
<thead>
<th>Zone</th>
<th>Popularity</th>
<th>Date</th>
</thead>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['location'] . "</td>";
echo "<td>" . $row['count(location)'] . "</td>";
echo "<td>" . $row['date'] . "</td>";
echo "</tr>";}
echo "</table>";
mysqli_close($con);
?>
<script>
$('table').DataTable( {
dom: 'Bfrtip',
"order": [[ 2, "desc" ]],
buttons: [
'copy',
{
extend: 'csv',
text: 'CSV',
extension: '.csv',
exportOptions: {
modifier: {
page: 'current'
}
},
title: 'table'
},
'pdf',
'print', ],
} );
</script>

I found a possible solution to your problem here
The recommended solutions are either follow this guide to specify a date-format for your date columns (since DataTables might not be able to detect it out of the box). You probably need to use moment.js to fix this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With