简体   繁体   English

我想要`start_time` 和`end_time` 计数如何得到这个?

[英]I want to `start_time` and `end_time` count how can get this?

How can count between start_time and end_time time如何在start_timeend_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.

相关问题 我想显示当前时间不在(column)start_time和end_time(column)之间的所有人员记录 - I want to display all personnel records that the current time is not between to the (column)start_time and end_time(column) sql使用start_time和end_time进行复杂数据排序 - sql Complex data sorting with start_time and end_time 获取每个日期 PHP 的 start_time 和 end_time 的总小时数? - Get total hours from start_time and end_time for each date PHP? 如何在yii2中使用start_time和end_time获取MySql中已有的记录? - How to fetch already existing records in MySql with start_time and end_time in yii2? 如果在范围内找到,如何找到 start_time 和 end_time 范围,然后检查 start_date 和 end_date - How to find the start_time and end_time range if found in the range then check start_date and end_date Laravel 5.1获取start_time和end_time之间的行(两个不同的字段) - Laravel 5.1 Fetch Rows between start_time and end_time (two different fields) 7个SQL行中的第一个开始时间和最后一个结束时间,仅显示1个SQL结果 - First start_time and last end_time from 7 SQL rows to show only 1 SQL result PayPal + PHP - 获取收款(开始时间/结束时间) - PayPal + PHP - Fetch incoming payments (start_time / end_time) 使用 PHP 从具有 start_time 和 end_time 的多维数组中查找总小时数? - Find total hours from multi-dimensional array with start_time and end_time using PHP? 它在end_time中给了我unsefined(NaN),所以我该如何解决 - it give me unsefined(NaN) in end_time so how can i resolve this
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM