Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 两种时间戳的比较_Php_Laravel - Fatal编程技术网

Php 两种时间戳的比较

Php 两种时间戳的比较,php,laravel,Php,Laravel,所以我想在一种情况下比较两个时间戳,以便在每次使用后每2小时制作一个活动按钮 此部分位于my Home.Blade.Php中 (cDelay_Vote)->这是我从数据库中获取的时间戳 @foreach($data as $per) @if ( date('Y-m-d H:i:s')->greaterThanOrEqualTo(strtotime($per->cDelay_Vote,'+2 hours'))) <form action="{{ route('home')}}"

所以我想在一种情况下比较两个时间戳,以便在每次使用后每2小时制作一个活动按钮

此部分位于my Home.Blade.Php中

(cDelay_Vote)->这是我从数据库中获取的时间戳

@foreach($data as $per)
@if ( date('Y-m-d H:i:s')->greaterThanOrEqualTo(strtotime($per->cDelay_Vote,'+2 hours')))
 <form action="{{ route('home')}}" method="post" enctype="multipart/form-data">
{{csrf_field()}}
 active Button
</form>
@else
 inactive Button
@endif
@endforeach

若你们在数据库中使用时间戳,你们可以这样做

@if (date('U') - $per->cDelay_Vote > 60*60*2)
@endif
如果是其他字段类型,则

@if (date('U') - strtotime($per->cDelay_Vote) > 60*60*2)
@endif

坏主意使用
@
符号来消除错误,如果你不写完整的代码和两个日期或者一个能帮助我们的例子,我将否决你的问题you@FernandoUrban这只是给我带来问题的一部分我不能使用代码和@符号它在Laravel框架代码中,我没有使用它来抑制errors@FernandoUrban在中使用
@
符号
.blade.php
文件不是错误抑制;这就是使用指令的方式(
@if
@foreach
@php
,等等)。在做出假设之前,请先熟悉Laravel和Blade。我建议您阅读有关碳的内容:。它提供了一系列用于日期/时间操作和比较的命令。因此,如果
cDelay\u Vote
是数据库中的DateTime列,您可以知道,它将自动将其转换为Carbon实例。
@if (date('U') - strtotime($per->cDelay_Vote) > 60*60*2)
@endif