<?php
$busno=3;
$busname = 'Bus3';
$startdate='09/03/2017';
$enddate='09/11/2017';
$value1 = value_table::where('Start Date', $startdate)->get();
$value1 = value_table::where('End Date', $enddate)->get();
我想查看开始日期&amp;结束日期不应与表中的任何日期冲突。
有没有机会通过一个查询来检查它?
答案 0 :(得分:0)
$value1 = value_table::where('Start Date', $startdate)->where('End Date', $enddate)->get();
答案 1 :(得分:0)
我认为你应该尝试这样:
$value1 = value_table::whereDate('Start Date', $startdate)
->whereDate('End Date', $enddate)
->get();
OR
$value1 = value_table::where('Start Date', $startdate)
->orWhere('End Date', $enddate)
->get();
希望这对你有用!!!
答案 2 :(得分:0)
1)如果您需要检查一对日期是否未包含在另一对日期中,请执行以下操作:
$value = value_table::where('Start date',">=",$endDate) //starts after your end date
->orWhere('End date',"<=",$startDate) //Ends before the other start date
2)要检查一对日期是否完全包含在另一对日期中,请执行以下操作:
$value = value_table::where('Start date',"<",$startDate)
->where('End date',">",$endDate);
3)要检查另一对中是否部分包含一对日期,请执行以下操作:
$value = value_table::where(function ($q) {
$q->where('Start date',"<",$startDate);
$q->where('End date',">", $startDate); //$startDate within
})->orWhere(function ($q) {
$q->where('Start date',"<",$endDate);
$q->where('End date',">", $endDate); //$endDate within
});