如何比较多个日期时间并将它们显示在一个视图中?
How to compare multiple datetimes and display them in one view?
我正在使用 carbon 来比较两个日期,最初我使用了两个静态变量,一个是 $Hnow = now()
,另一个是 $Hlim = Carbon :: Create($year, $month, $day, $hourM, $minute, $second);
比较如下:
$intervalH = $Hnow-> diffInHours ($Hlim);
很好,它对我来说很完美,但现在我必须让它适应一个数据库,我有几个时间戳,而不是有一个静态的 $ Hlim,我有很多日期,这是目前的限制一个工作。如何将 table 中的每个日期与当前日期进行比较并按顺序显示这些数据?我知道时间戳不能与碳相比,所以我先转换它,但它没有显示任何捕获日期。
控制器:
<?php
namespace App\Http\Controllers;
use App\pamatrixinf;
use App\Periodicity;
use Illuminate\Http\Request;
use App\Alertnotification;
use Carbon\Carbon;
use DateTime;
use App\pawork;
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),以便了解每个作业还剩多少时间才能完成其交货时间。
改变你的查询,它像这样在行下面,因为你直接传递包含查询结果的 $dateli
和 strtotime
函数需要一个字符串。
希望对你有帮助
$dateli=pamatrixinf::select('pamatrixinf.dateen')
->where('pamatrixinf.read_at','=',0,'AND')
->where('codpaarea', '=', auth()->user()->codarea)
->get()
->toArray();
$datelim= strtotime($dateli[0]['dateen']);
我正在使用 carbon 来比较两个日期,最初我使用了两个静态变量,一个是 $Hnow = now()
,另一个是 $Hlim = Carbon :: Create($year, $month, $day, $hourM, $minute, $second);
比较如下:
$intervalH = $Hnow-> diffInHours ($Hlim);
很好,它对我来说很完美,但现在我必须让它适应一个数据库,我有几个时间戳,而不是有一个静态的 $ Hlim,我有很多日期,这是目前的限制一个工作。如何将 table 中的每个日期与当前日期进行比较并按顺序显示这些数据?我知道时间戳不能与碳相比,所以我先转换它,但它没有显示任何捕获日期。
控制器:
<?php
namespace App\Http\Controllers;
use App\pamatrixinf;
use App\Periodicity;
use Illuminate\Http\Request;
use App\Alertnotification;
use Carbon\Carbon;
use DateTime;
use App\pawork;
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),以便了解每个作业还剩多少时间才能完成其交货时间。
改变你的查询,它像这样在行下面,因为你直接传递包含查询结果的 $dateli
和 strtotime
函数需要一个字符串。
希望对你有帮助
$dateli=pamatrixinf::select('pamatrixinf.dateen')
->where('pamatrixinf.read_at','=',0,'AND')
->where('codpaarea', '=', auth()->user()->codarea)
->get()
->toArray();
$datelim= strtotime($dateli[0]['dateen']);