我有收藏集promotions
,每个促销活动都有很多exceptions
:
foreach ($promotions as $p) {
$t = $p->exceptions()
->where('sunday','on')
->whereDate('start','<=', $c_date)
->whereDate('end','>=', $c_date)
->get()
->sortBy('promotion_id');
echo $t->min('start'). ' from: '.$t->min('start_time') .' ';
echo $t->max('end') . ' to: '.$t->max('end_time').'</br>';
}
由于促销活动有很多例外,因此每次促销的最小日期和最大日期我都需要知道。
上面的代码运行良好,但是它使用'start'作为字符串而不是日期,结果无效。
如何从集合中获取最小日期和最大日期。
答案 0 :(得分:1)
理想情况下,明智的做法是,每个开始和结束都具有一个DATETIME字段,而不要分开日期和时间(这可能会导致您出错)。但是,如果您真的想要分开:
start
和end
作为日期存储在数据库中,然后指定诸如here start
和end
的格式更改为“ YYYY-MM-DD”