如果今天日期在 laravel 中的开始日期和结束日期之间,如何在视图中显示单个数据?



我有录取表,其中有id,school_id,start_date,end_date等,如果今天的日期在拉拉维尔雄辩的start_date和end_Date之间,我想显示单个数据

应用下面的代码,您可以获得当前日期的最新数据

$currentDate = date('Y-m-d');
$result = my_table::where(DB::raw('DATE(start_date)'), '<=' , $currentDate)
       ->where(DB::raw('DATE(end_Date)'), '>' , $currentDate)
       ->orderBy('id','desc')
       ->first();
`$start_date = date('2018-01-01');
$end_date = date('2018-05-02');
Adminssion::whereBetween(CarbonCarbon::now()->toDateString(), [$start_date, $end_date])->get();`

碳现在()函数将为您提供当前的日期和时间。而toDateString()函数只给你今天的日期。使用 whereBetween() 函数,您可以比较 start_date 和 end_date 之间的当前日期。

最新更新