【发布时间】:2016-08-02 18:25:58
【问题描述】:
我有一个appointments table,我将约会开始日期和时间存储在datetime 字段中。我有很多方法可以用来获取在特定日期或两个给定日期之间开始的约会。例如:
日历类:
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();
}
【问题讨论】: