Php 其中,型号日期在laravel上,不考虑年份
我想显示日期在05-27和05-29(m-d)之间的数据,而不考虑年份 示例查询可能如下所示:Php 其中,型号日期在laravel上,不考虑年份,php,laravel,eloquent,Php,Laravel,Eloquent,我想显示日期在05-27和05-29(m-d)之间的数据,而不考虑年份 示例查询可能如下所示: employee::whereBetween('birthday', array('05-27', '05-29'))->get(); 例如,如果我有5项: 1989-05-27, 1989-05-29, 1992-05-27, 1993-05-27, 1993-05-28 应显示所有项目。这是可能的吗?您可以这样创建来实现它 Employee::select('*') ->wh
employee::whereBetween('birthday', array('05-27', '05-29'))->get();
例如,如果我有5项:
1989-05-27,
1989-05-29,
1992-05-27,
1993-05-27,
1993-05-28
应显示所有项目。这是可能的吗?您可以这样创建来实现它
Employee::select('*')
->whereMonth('birthday', '=', '5')
->where(function ($query) {
$query->whereDay('birthday', '>=', 27)
->whereDay('birthday', '<=', 29);
})
->get();
Employee::选择('*')
->whereMonth('生日','=','5')
->其中(函数($query){
$query->whereDay('birth','>=',27)
->whereDay(“生日”),在处理日期时,请始终尝试使用Carbon
$first = Carbon::create(null,5,27);
$second = Carbon::create(null,5,29);
$birthdayBoys = employee::whereBetween('birthday',[$first,$second])->get();
编辑
如果您的生日
列的数据不是碳的实例
请在您的员工
模型中添加此行:
protected $dates = ['birthday']
它会自动将您的生日值作为Carbon
实例存储在数据库中。您是否试图在这两天之间查找数据库中的所有记录,而不考虑年份?是的,先生,有一种简单的方法吗?如果使用不同的月份如何?例如11-30和12-01。也许您可以使用closure-like on查询不同月份的日期。