我的申请有问题。在那里,我想搜索我的专栏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'] = ???
答案 0 :(得分:1)
使用diffInHours()方法,因为你正在使用碳。
$mulai = Carbon::createFromFormat('H:i', Request::input('mulai'));
$durasi = Carbon::createFromFormat('H:i', Request::input('durasi'));
$total = $durasi->diffInHours($mulai);
答案 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'));