如何比较多个日期时间并在一个视图中显示它们?



我用碳来比较两个日期,最初我使用了两个静态变量,一个是$Hnow = now()的,另一个是$Hlim = Carbon :: Create($year, $month, $day, $hourM, $minute, $second);比较如下:  

$intervalH = $Hnow-> diffInHours ($Hlim);

好吧,它对我来说非常适合,但现在我必须将其适应数据库,其中我有几个时间戳,并且我有很多日期,而不是静态的$ Hlim,这是展示作品的限制。如何将表格中的每个日期与当前日期进行比较,并有序地显示这些数据?我知道时间戳无法与碳进行比较,所以我先转换了它,但它没有显示任何捕获的日期。

控制器:

<?php
namespace AppHttpControllers;
use Apppamatrixinf;
use AppPeriodicity;
use IlluminateHttpRequest;
use AppAlertnotification;
use CarbonCarbon;
use DateTime;
use Apppawork;
class fen extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function index()
{
$hour= 14;
$minute= 0;
$second=0;
$year= date("Y");
$month= date("m");
$day=date("d");
$hourM=date("H");
$dayy= now();
$dateli=pamatrixinf::select('pamatrixinf.dateen')
->where('pamatrixinf.read_at','=',0,'AND')
->where('codpaarea', '=', auth()->user()->codarea)
->get();
$datelim= strtotime($dateli);
$datedif=Carbon::Create($year,$month,$day,$hourM,$minute,$second);
$dateend= $datedif->addHour();
$intervalH= $dayy->diffInHours($datelim);
$intervalM= $dayy->diffInMinutes($dateend);

return view('fen.index', [
'Works' => Periodicity::select('paperiodicity.descriptionp','pamatrixinf.description', 'pamatrixinf.codpar')
->join('pamatrixinf', 'pamatrixinf.cod_paperiodicity', '=', 'paperiodicity.cod')
->where('pamatrizinfoperio.read_at', '=', 0, 'AND')
->where('pamatrizinfoperio.codpaarea', '=',auth()->user()->codarea)
->get(),
'Periodores' => $intervalH,
'Periodoresm' => $intervalM,
'Hactual' => $dayy,
'Hlimit' => $datelim

]);
}
}

我的观点是:

@extends('layouts.app')
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header"><h4>Fenecer</h4></div>
<div class="card-body">
@if (session('status'))
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
@endif
Welcome {{Auth::user()->name}}, the work for today is:
@foreach($Works as $work)
<li class="list-group-item">
La informacion por mandar llamada
<p style="color:red;"> <b>{{$trabajo->descripcion}}</b> </p>
@if($Hactual<$Hlimit)
is about to end in
{{$Periodores}} Hours and
{{$Periodoresm}} Minutes, the limit is {{$Hlimit}} and the date actual is {{$Hactual}}.
@elseif($Hactual>$Hlimit)
<p style="color:red;"> <b> It has passed away please we inform the manager. The work died on {{$Hlimit}} and the actual date is {{$Hactual}} </b> </p>
@endif
</li>
@endforeach

</div>
</div>
</div>
</div>
</div>

如您所见,我想做的是在视图中显示小时差 ($datelim(,以便知道每个作业还剩多少来完成其交付时间。

更改您的查询,它位于这样的行下方,因为您直接传递包含查询结果的$datelistrtotime函数需要一个字符串。 我希望它有所帮助

$dateli=pamatrixinf::select('pamatrixinf.dateen')
->where('pamatrixinf.read_at','=',0,'AND')
->where('codpaarea', '=', auth()->user()->codarea)
->get()
->toArray();
$datelim= strtotime($dateli[0]['dateen']);

最新更新