两个值之间的日期 - Laravel SQL
Date between two values - Lavarel SQL
我的结构 table 是这样的:Start_date
End_date
现在今天是,我应该去获取所有数据,包括Start_Date
和End_Date
,我能做什么?
我试过
SELECT *
FROM text
WHERE Start_date BETWEEN '2021-10-10' AND '2021-10-08'
OR End_date BETWEEN '2021-10-08' AND '2021-10-10
但无济于事...
Laravel 中的 whereBetween
方法将确定项目值是否在给定范围内。
$start = '2021-10-08';
$end = '2021-10-10';
Text::whereBetween('start_date', [$start, $end])
->whereBetween('end_date', [$start, $end])
->get();
- 如果您只想获取从开始到结束日期的数据,您可以使用此 eloquent 代码
$start_date = "2020-10-20";
$end_date = "2021-10-20";
Text::where(function ($wh) use ($start_date, $end_date) {
$wh->whereBetween('Start_date', [$start_date, $end_date])->orwhereBetween('End_date', [$start_date, $end_date]);
})->get();
这是来自上述 eloquent 代码的原始查询
select * from `users` where (`Start_date` between '2020-10-20' and '2021-10-20' or `End_date` between '2020-10-20' and '2021-10-20')
- 如果您想查找从开始日期到结束日期的数据,包括今天的日期,您可以使用此 eloquent 代码
$start_date = "2020-10-20";
$end_date = "2021-10-20";
Text::where(function ($wh) use ($start_date, $end_date) {
$today_date = date('Y-m-d');
$wh->where(function ($or_where) use ($start_date, $end_date) {
$or_where->whereBetween('Start_date', [$start_date, $end_date])
->orwhereBetween('End_date', [$start_date, $end_date]);
})->orwhereRAW("('{$today_date}' between `Start_date` and `End_date`)");
})->get();
这是来自上述 eloquent 代码的原始查询
select * from `text` where ((`Start_date` between '2020-10-20' and '2021-10-20' or `End_date` between '2020-10-20' and '2021-10-20') or ('2021-10-09' between `Start_date` and `End_date`))
我的结构 table 是这样的:Start_date
End_date
现在今天是,我应该去获取所有数据,包括Start_Date
和End_Date
,我能做什么?
我试过
SELECT *
FROM text
WHERE Start_date BETWEEN '2021-10-10' AND '2021-10-08'
OR End_date BETWEEN '2021-10-08' AND '2021-10-10
但无济于事...
Laravel 中的 whereBetween
方法将确定项目值是否在给定范围内。
$start = '2021-10-08';
$end = '2021-10-10';
Text::whereBetween('start_date', [$start, $end])
->whereBetween('end_date', [$start, $end])
->get();
- 如果您只想获取从开始到结束日期的数据,您可以使用此 eloquent 代码
$start_date = "2020-10-20";
$end_date = "2021-10-20";
Text::where(function ($wh) use ($start_date, $end_date) {
$wh->whereBetween('Start_date', [$start_date, $end_date])->orwhereBetween('End_date', [$start_date, $end_date]);
})->get();
这是来自上述 eloquent 代码的原始查询
select * from `users` where (`Start_date` between '2020-10-20' and '2021-10-20' or `End_date` between '2020-10-20' and '2021-10-20')
- 如果您想查找从开始日期到结束日期的数据,包括今天的日期,您可以使用此 eloquent 代码
$start_date = "2020-10-20";
$end_date = "2021-10-20";
Text::where(function ($wh) use ($start_date, $end_date) {
$today_date = date('Y-m-d');
$wh->where(function ($or_where) use ($start_date, $end_date) {
$or_where->whereBetween('Start_date', [$start_date, $end_date])
->orwhereBetween('End_date', [$start_date, $end_date]);
})->orwhereRAW("('{$today_date}' between `Start_date` and `End_date`)");
})->get();
这是来自上述 eloquent 代码的原始查询
select * from `text` where ((`Start_date` between '2020-10-20' and '2021-10-20' or `End_date` between '2020-10-20' and '2021-10-20') or ('2021-10-09' between `Start_date` and `End_date`))