我一直试图用碳来计算两个日期的差值,这样我就可以计算花费的百分比,但它一直输出0
下面是为了得到开始日期和结束日期之间的差异。
public function validityMeter($start_date, $end_date){
$start_date = Carbon::parse($start_date);
$diff =$start_date->diffInDays($end_date);
return $diff;
}
public function percentageMeter($start_date, $end_date){
$diff = Carbon::parse($start_date);
$diff = $diff->diffInDays(Carbon::now()->format("Y-m-d"));
$multiple = $diff * 100;
$percentage = $multiple / $this->validityMeter($start_date, $end_date);
return $percentage;
}
第二种方法(percentageMeter())用于获取当前日期和start\u日期之间的差值,之后我将使用这两种方法的值来获取百分比。
刀片模板
<div class="progress progress-xs">
<div class="progress-bar progress-bar-green" style="width: {{$obj->percentageMeter($booking->start_date, $booking->end_date)}}"> </div>
</div>
控制器
public function type($type){
// dd(Carbon::now()->format("Y-m-d"));
$booking = Booking::where("approve", true)
->where("end_date", '>=', Carbon::now()->format("Y-m-d"))
->where("plan_type", $type)
->get();
// dd($booking);
$obj = new Plan;
$counter= 1;
return view("admin.plan.type")->with("booking", $booking)
->with("counter", $counter)
->with("obj", $obj);
}
$start_date = 2018-05-06 00:00:00;
$end_date = 2018-12-30