如何从数据表中的最新日期和时间排序

问题描述

我在对数据表中的日期和时间进行排序时遇到问题。排序的实际结果是这样的。

Jan 13,2021 12:03 PM
Jan 13,2021 11:30 AM
Jan 13,2021 09:03 AM
Jan 13,2021 08:32 PM <-- Must be on top
Jan 13,2021 06:33 AM
Jan 13,2021 01:15 PM <-- Must be 2nd on top

结果没有按照最近的时间排序。无论上午还是下午,它都根据数字进行排序。

HTML 代码

<table class="table table-bordered" id="example" width="100%" cellspacing="0">
     <thead>
         <th class="text-center">Name</th>
         <th class="text-center">Date & Time Filled</th>
     </thead>
     <tbody>
          @foreach($users as $user)
          <tr>
              <td>{{ $user->name}}</td>
              <td>{{ date('M d,Y h:i A',strtotime($user->created_at)) }}</td>
          </tr>
          @endforeach
     </tbody>
</table>

我的 JavaScript

$(document).ready(function() {
   $('#example').DataTable( {
      "order": [[ 1,"desc" ]] //sort code
   });
});

laravel 中的控制器代码

$users:: User::latest('created_at')->get();

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)