求date类型的时间,差值,并排序

mysql中 sql语句可以这样写:

select * , (to_days(curdate()) - to_days(`end_date`)) as date_diff from `tab` order by date_diff asc ;

laravel模型中,可以这样写:

StandingBook::selectRaw("* ,(to_days(curdate()) - to_days(`end_date`)) as date_diff")
            ->orderBy("date_diff","asc")
            ->paginate($limit)
            ->toArray();

你可能感兴趣的:(求date类型的时间,差值,并排序)