如果今天日期介于 laravel 中的开始日期和结束日期之间,我如何在视图中显示单个数据?
How can i show single data in view if today date is in between start date & end date in laravel?
我有入场券 table,其中有 id、school_id、start_date、end_date 等,如果今天的日期介于 [=14] 之间,我想显示单个数据=] & end_Date 在 laravel eloquent
应用下面的代码你可以获得当前日期的最新数据
$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(Carbon\Carbon::now()->toDateString(), [$start_date, $end_date])->get();`
carbon now() 函数将为您提供当前日期和时间。而 toDateString() 函数只会给你今天的日期。使用 whereBetween() 函数,您可以比较 start_date 和 end_date.
之间的当前日期
我有入场券 table,其中有 id、school_id、start_date、end_date 等,如果今天的日期介于 [=14] 之间,我想显示单个数据=] & end_Date 在 laravel eloquent
应用下面的代码你可以获得当前日期的最新数据
$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(Carbon\Carbon::now()->toDateString(), [$start_date, $end_date])->get();`
carbon now() 函数将为您提供当前日期和时间。而 toDateString() 函数只会给你今天的日期。使用 whereBetween() 函数,您可以比较 start_date 和 end_date.
之间的当前日期