我有一个appointments table
其中我将预约开始日期和时间存储在datetime
字段中。我有很多方法可用于获取从特定日期开始或在两个给定日期之间开始的约会。例如:Laravel在日期之间搜索没有结果时间相同(从今天获得结果)
日历类:
public function today()
{
$start = Carbon::now()->hour('00')->minute('00')->second('00');
$end = Carbon::now()->hour('23')->minute('59')->second('00');
return Appointment::getAppointments($this->start, $this->end);
}
// public function tomorrow();
// public function thisMonth();
预约型号:
public static function getAppointments($start, $end)
{
return static::whereBetween('date', array(
$start->format('Y-m-d H:i'),
$end->format('Y-m-d H:i')
))->get();
}
正如你看到的,我需要设置小时,分钟和秒,因为否则将不会返回任何结果,如果开始日期和结束日期相同。是否可以简单地做到以下几点,并仍然从那个日期获得结果?
public function today()
{
$start = Carbon::now();
$end = Carbon::now();
return Appointment::getAppointments($this->start, $this->end);
}
public static function getAppointments($start, $end)
{
return static::whereBetween('date', array(
$start->format('Y-m-d'),
$end->format('Y-m-d')
))->get();
}
实际上,我用这个日期间下跌寻找生日,但按月和日。不知道我也可以用这样的约会这样的。太棒了,谢谢:) – Hardist