微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

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

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 举报,一经查实,本站将立刻删除。