繁体   English   中英

我想比较当前日期的日期,如果日期介于日期之间,则禁用按钮

[英]I want to compare the dates from current date and Disable the button if the date lies between the dates

如果当前日期在三个月之间,我想禁用我的按钮。

我尝试使用PHP和JavaScript组合,但对我没有用

PHP代码

@php($found = false)

@foreach($doctors as $doctor)
        @if($doctor->transaction_id != NULL && $doctor->plan != NULL && $doctor->cabin == "Cabin 1" && $doctor->day =="Friday" && $doctor->time == "8.00 - 10.00") 
            <?php
            $found = true;
            $time = substr($doctor->timestamp,10);
            ?>
        @endif
@endforeach

@if($found)
    <button type="button" id="btnn" onload="loadImage()" class="btn btn-info btn-lg matchButton" data-toggle="modal" data-target="#myModal">8.00 - 10.00</button>&nbsp;
@else
    <button type="button" onload="loadImage()" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">8.00 - 10.00</button>&nbsp;
@endif

JavaScript代码

<script>
  function loadImage(){
     var time = <?php $time;?>
     <?php
     $dt = strtotime($time);
     $time2= date("Y-m-d", strtotime("+3
       month", $dt));
     ?>
     var time2 = <?php $time2;?>
     var today = new Date();
     var dd = today.getDate();
     var mm = today.getMonth()+1;
     var yyyy = today.getFullYear();

     if(dd<10)
     {
         dd='0'+dd;
     }

     if(mm<10)
     {
         mm='0'+mm;
     }
     <?php
     $dt = strtotime($time);
     echo date("Y-m-d", strtotime("+3month", $dt));
     ?>
     var bt = document.getElementById('btnn');
     today = yyyy+'-'+mm+'-'+dd;
     if(today>time && today<time2)
     {
         bt.disabled = true;
     }
     else{
         bt.disabled = false;
     }
  }
</script>

我从Timestamp中提取了一个子字符串YYYY-MM-DD

这一切都可以在Blade中使用Carbon完成:

@if (! \Carbon\Carbon::now()->between(\Carbon\Carbon::parse($startingDate), \Carbon\Carbon::parse($endingDate)))
    YOUR BUTTON CODE, IF CURRENT DATE IS NOT BETWEEN $startingDate and $endingDate
@endif

设置$startingDate$endingDate ,此代码将检查当前日期是否在这两个日期之间。 如果是,则什么也不会显示。 如果不是,该按钮将显示。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM