You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
638 B
PHP

<?php
use Carbon\Carbon;
$file = fopen("/home/ayush/file.csv", "r");
$rows = [];
while (($data = fgetcsv($file)) !== false) {
$rows[] = $data;
}
fclose($file);
$header = array_shift($rows);
usort($rows, function ($a, $b) {
$dt1 = Carbon::createFromFormat("d/m/Y H:i:s", $a[15])->settings([
"timezone" => "Asia/Kolkata"
]);
$dt2 = Carbon::createFromFormat("d/m/Y H:i:s", $b[15])->settings([
"timezone" => "Asia/Kolkata"
]);
return $dt1->greaterThanOrEqualTo($dt2);
});
$file = fopen("/home/ayush/file_sorted.csv", "w");
fputcsv($file, $header);
foreach ($rows as $r) {
fputcsv($file, $r);
}
fclose($file);