This issue is happening across the entire application...
I have datatables & charts:
- Datatables don't sort by dateTime correctly, aka
Started
Column.
- Charts always starts with the latest date...not by order:
I am using Carbon
for datatables like this:
->editColumn('startDateTime', function ($report) {
return Carbon::parse($report->startDateTime)->format('d M, Y');
})
For the charts, returning data as json then format the date:
$data = TrafficViolation::select('id', 'violationDateTime')
->orderBy('violationDateTime')
->get()
->groupBy(function($data) {
return Carbon::parse($data['violationDateTime'])->format('M');
});
The column type of these dates are DateTime
in the database.
What's frustrating is that there is a datatable called Audit Log
that came with the theme (Metronic 8) and it's sorting the date correctly here (created at
):
And looking to its controller:
->editColumn('created_at', function (Activity $model) {
return $model->created_at->format('d M, Y H:i:s');
})
Looking at the Model there isn't anything related to Carbon
or date functions there, noting that the data type of created_at
is timestamp
.
I tried:
- Changing data type to
timestamp
instead ofdatetime
. - Copying the same code of
audit log
, no need forCarbon
, I get an errorformat() unknown
.