laravel 5.1小时之间的距离

时间:2016-05-11 03:28:30

标签: php laravel laravel-5 laravel-5.1 laravel-routing

我的申请有问题。在那里,我想搜索我的专栏mulai& amp; durasi列中的结果总计,列总数是距离数据列mulai直到数据列durasi的结果。有什么想法吗?

$simpan= array();
    $simpan['nama']=Request::input('nama');
    $simpan['tanggal']=Request::input('tanggal');
    $simpan['deskripsi']=Request::input('deskripsi');
    $simpan['mulai']=Carbon::createFromFormat('H:i', Request::input('mulai'))->toTimeString();
    $simpan['durasi']=Carbon::createFromFormat('H:i', Request::input('durasi'))->toTimeString();
    $simpan['total'] = ???

2 个答案:

答案 0 :(得分:1)

使用diffInHours()方法,因为你正在使用碳。

$mulai  = Carbon::createFromFormat('H:i', Request::input('mulai'));
$durasi = Carbon::createFromFormat('H:i', Request::input('durasi'));
$total  = $durasi->diffInHours($mulai);

在这里查看 http://carbon.nesbot.com/docs/#api-difference

答案 1 :(得分:0)

您必须将durasi时间添加到mulai。代码:

$mulai  = Carbon::createFromFormat('H:i', Request::input('mulai'));
$durasi = Carbon::createFromFormat('H:i', Request::input('durasi'));
$total  = $mulai->addHours($durasi->format('H'))->addMinutes($durasi->format('i'));
dd($total->format('%h:%I'));