如何使用查询生成器计算 Laravel 中的两个相关日期?
How to count two related dates in Laravel using Query Builder?
我有这个日期列表
我想计算连续每个日期之间的时间超过 24 小时的次数...试过这个..
$tiempo1 = DB::table('incidencia_tiempo')
->whereTime('time', '>', '0000-00-00 24:00:00')
->count();
时间和创建时间之间...我想计算...如果两次时间之间的时间大于 24 小时,则将 +1 添加到计数中
我要比较created_at和时间,我不知道怎么比较
你的意思是什么时间超过 24 小时?
试试这个方法来比较和计算日期
$text_count = Text::whereBetween('created_at', [$date1, $date2])->count();
首先,您必须 运行 简单查询以获取所有数据,例如
$tiempo1 = DB::table('incidencia_tiempo')->get();
并为此查询数据添加一个循环
$count = 0;
foreach($tiempo1 as $time) {
$start = new Carbon($time->time);
$end = new Carbon($time->created_at);
$hours = $start->diff($end)->format('%H');
if ($hours > 24){
$count++;
}
}
希望这会有所帮助:)
使用TIMESTAMPDIFF()
获取两个日期时间之间的时间,
如果要算time
比created_at
24小时高
$count = DB::table('incidencia_tiempo')
->where(DB::raw('TIMESTAMPDIFF(HOUR, time, created_at)'), '>', 24)
->count();
如果要计算两个日期时间之间的时差超过 24 小时:
$count = DB::table('incidencia_tiempo')
->where(DB::raw('ABS(TIMESTAMPDIFF(HOUR, time, created_at))'), '>', 24)
->count();
我有这个日期列表
我想计算连续每个日期之间的时间超过 24 小时的次数...试过这个..
$tiempo1 = DB::table('incidencia_tiempo')
->whereTime('time', '>', '0000-00-00 24:00:00')
->count();
时间和创建时间之间...我想计算...如果两次时间之间的时间大于 24 小时,则将 +1 添加到计数中
我要比较created_at和时间,我不知道怎么比较
你的意思是什么时间超过 24 小时?
试试这个方法来比较和计算日期
$text_count = Text::whereBetween('created_at', [$date1, $date2])->count();
首先,您必须 运行 简单查询以获取所有数据,例如
$tiempo1 = DB::table('incidencia_tiempo')->get();
并为此查询数据添加一个循环
$count = 0;
foreach($tiempo1 as $time) {
$start = new Carbon($time->time);
$end = new Carbon($time->created_at);
$hours = $start->diff($end)->format('%H');
if ($hours > 24){
$count++;
}
}
希望这会有所帮助:)
使用TIMESTAMPDIFF()
获取两个日期时间之间的时间,
如果要算time
比created_at
24小时高
$count = DB::table('incidencia_tiempo')
->where(DB::raw('TIMESTAMPDIFF(HOUR, time, created_at)'), '>', 24)
->count();
如果要计算两个日期时间之间的时差超过 24 小时:
$count = DB::table('incidencia_tiempo')
->where(DB::raw('ABS(TIMESTAMPDIFF(HOUR, time, created_at))'), '>', 24)
->count();