我需要计算查询列中的日期与今天在循环内的日期之间的差,以收集货件的寿命
我尝试使用datediff将发货日期作为第一个参数,将today()作为第二个参数
@foreach($shipments as $shipment)
<tr>
<td data-title="id">{{$shipment->id}}</td>
<td class=tracking data-title="tracking">{{$shipment->tracking}}</td>
<td data-title="PartNumber">{{$shipment->PartNumber}}</td>
<td data-title="DateShipped">{{$shipment->DateShipped}}</td>
<td data-title="age" value={{$shipment->DateShipped}}-today()><?php echo date_diff({{$shipment->DateShipped}},today())?></td>
<td data-title="Qtyorder">{{$shipment->Qtyorder}}</td>
<td data-title="QtyShipped">{{$shipment->QtyShipped}}</td>
<td data-title="QtyBckorder">{{$shipment->QtyBckorder}}</td>
<td data-title="purchaseOrder">{{$shipment->purchaseOrder}}</td>
<td data-title="OrderNumber">{{$shipment->OrderNumber}}</td>
<td value={{$shipment->Location}}>{{$shipment->Location}}</td>
<td data-title="paperwork">{{$shipment->paperwork}}</td>
<td data-title="VMIreceived">{{$shipment->VMIreceived}}</td>
<td data-title="VMIticketNumber">{{$shipment->VMIticketNumber}}</td>
<td data-title="VMILRB">{{$shipment->VMILRB}}</td>
<td><a href="{{ route('shipment.edit',$shipment->id)}}" class="btn btn-primary">Edit</a></td>
<td>
<form action="{{ route('shipment.destroy', $shipment->id)}}" method="post">
@csrf
@method('DELETE')
<button class="btn btn-danger" type="submit">Delete</button>
</form>
</td>
</tr>
@endforeach
答案 0 :(得分:0)
@foreach($shipments as $shipment)
<tr>
<td data-title="id">{{$shipment->id}}</td>
<td class=tracking data-title="tracking">{{$shipment->tracking}}</td>
<td data-title="PartNumber">{{$shipment->PartNumber}}</td>
<td data-title="DateShipped">{{$shipment->DateShipped}}</td>
<td data-title="age" data-value="{{(int) floor((time() - strtotime('2019-04-29')) / (60 * 60 * 24))}}"></td>
<td data-title="Qtyorder">{{$shipment->Qtyorder}}</td>
<td data-title="QtyShipped">{{$shipment->QtyShipped}}</td>
<td data-title="QtyBckorder">{{$shipment->QtyBckorder}}</td>
<td data-title="purchaseOrder">{{$shipment->purchaseOrder}}</td>
<td data-title="OrderNumber">{{$shipment->OrderNumber}}</td>
<td value={{$shipment->Location}}>{{$shipment->Location}}</td>
<td data-title="paperwork">{{$shipment->paperwork}}</td>
<td data-title="VMIreceived">{{$shipment->VMIreceived}}</td>
<td data-title="VMIticketNumber">{{$shipment->VMIticketNumber}}</td>
<td data-title="VMILRB">{{$shipment->VMILRB}}</td>
<td><a href="{{ route('shipment.edit',$shipment->id)}}" class="btn btn-primary">Edit</a></td>
<td>
<form action="{{ route('shipment.destroy', $shipment->id)}}" method="post">
@csrf
@method('DELETE')
<button class="btn btn-danger" type="submit">Delete</button>
</form>
</td>
</tr>
@endforeach
它将为您带来天数差异(例如,在24-48小时内,它将显示1天,在48-72小时内,将显示2天)
(60 * 60 * 24)
这是minute
* second
* day
,
例如,如果要以小时为单位显示差异,请删除day
,以小时为单位的差异(60 * 60而不是60 * 60 * 24)
答案 1 :(得分:0)
<td>{{ $shipment->DateShipped->diffForHumans() }}</td>