我正在使用 Carbon PHP 库。重复问题中的答案使用 PHP 的内置函数。
下面是我用来查找日期范围($userDateStart
和$userDateEnd
)是否在另一个日期范围($couponStart and
$couponEnd`)中的代码,它工作正常,没有任何错误,但我不知道如何找到重叠/存在的日期在这个日期范围内吗?
我正在使用的库是http://carbon.nesbot.com/docs/
在这种情况下,预期结果应该是 4..希望你能帮助我。
$userDateStart = Carbon::createFromFormat('Y-m-d','2015-06-26');
$userDateEnd = Carbon::createFromFormat('Y-m-d','2015-06-29');
$couponStart = Carbon::createFromFormat('Y-m-d','2015-06-26');
$couponEnd = Carbon::createFromFormat('Y-m-d','2015-10-31');
if(($userDateStart >= $couponStart && $userDateEnd <= $couponEnd) ||
($couponStart >= $userDateStart && $couponEnd <= $userDateEnd)){
die("Yes,The date is within this date range");
}
die("No,It is not within this date range");