在我的控制器中
$ldate = date('Y-m-d ');
$b = DB::table('warehouse_products_sell')
->select([
'warehouse_products_sell.dueto_date'
])
->get();
我的输出
$b->dueto_date = 2017-10-26
$ldate = 2017-10-07
我想检查
if ($b->dueto_date - $ldate < 5 ){
alert('hi')
}
注意:5(天)
不知道该怎么做。
答案 0 :(得分:2)
Laravel使用Carbon
库,因此您可以轻松地依赖它的酷API,
这是一个简单的例子:
use Carbon\Carbon;
$dt1 = Carbon::createFromFormat('Y-m-d', $b->dueto_date);
$dt2 = Carbon::createFromFormat('Y-m-d', $ldate);
$diff = $dt1->diffInDays($dt2);
if ($diff < 5) {
echo "hi";
}
答案 1 :(得分:2)
$DueDate = new DateTime($b->dueto_date); // Due Date
$ldate = new DateTime('Y-m-d') // Your date
$interval = $DueDate->diff($ldate);
if($interval->d < 5){
echo '<script>alert("less than 5 days remaining")</script>';
}
答案 2 :(得分:1)
如下所示:
$days = floor((strtotime($b->dueto_date)- strtotime($your_date))/ (60 * 60 * 24));
if ($days < 5 ){
echo "less than 5 days remaining"; //it's php not jQuery
}else{
echo "$days days remaining";
}