[英]I want to `start_time` and `end_time` count how can get this?
How can count between start_time
and end_time
time如何在
start_time
和end_time
时间之间计数
$time_all = Carbon::now()->toArray();
if ($input['type'] == 'start') {
/* $data = [
'start_time' => $time, 'contract_id' => $input['job_id'],'engineer_id' => $userid, 'type' => 'start'
];*/
$start_time = JobTimingLog::create([
'start_time' => $time, 'contract_id' => $input['job_id'],'engineer_id' => $userid, 'type' => 'start'
])->id;
$arr = array("status" => 200, "message" => "start_time Add Successfully", "data" => array('start_time' => $time, 'id' => $start_time));
} else if ($input['type'] == 'end') {
$data_end = DB::table('job_timing_logs')->where('contract_id', $input['job_id'])->where('id', $input['id'])->update(['end_time' => $time, 'type' => 'end']);
$arr = array("status" => 200, "message" => "end_time update Successfully", "data" => $times);
}
Now I want to count between start_time and end_time现在我想在 start_time 和 end_time 之间计数
Since you didn't specify where did you get the $time
variable content and in what format is it, I'll assume $time
is start datetime and $end_time
is end datetime and you want to take the time difference between those two.由于您没有指定从何处获取
$time
变量内容以及它的格式是什么,我假设$time
是开始日期$time
而$end_time
是结束日期时间,并且您想计算这两者之间的时间差。 It can be done using Carbon difference package like this:可以使用Carbon 差异包来完成,如下所示:
// Assume $time = '2019-12-06 00:00:00' and $end_time = '2019-12-06 18:00:00'
$start_time = Carbon::parse($time); // Parse the datetime to Carbon object first
$end_time = Carbon::parse($end_time);
$diff_in_hours = $start_time->diffInHours($end_time);
$diff_in_minutes = $start_time->diffInMinutes($end_time);
$diff_in_seconds = $start_time->diffInSeconds($end_time);
You can use Carbon's difference methods to get the difference between two Carbon objects.您可以使用 Carbon 的差异方法来获取两个 Carbon 对象之间的差异。
For example, if you wanted the difference between $start_date
and $end_date
in a CarbonInterval object, you could do something like this:例如,如果您想要 CarbonInterval 对象中
$start_date
和$end_date
之间的差异,您可以执行以下操作:
$start_date->diffAsCarbonInterval($end_date)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.