具有可空日期的日期范围重叠 [英] Date Range Overlap with Nullable Dates
本文介绍了具有可空日期的日期范围重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找此处提出的问题的扩展答案:
I'm looking for an extended answer to the question asked here:
,其中任一日期范围内的任何日期都可以为null.我已经提出了以下解决方案,但不确定是否可以进一步简化.
where any of the dates in either date range can be null. I've come up with the following solution, but I'm not sure if it can be simplified further.
(StartA == NULL || StartA <= EndB) &&
(EndA == NULL || EndA >= StartB) &&
(StartB == NULL || StartB <= EndA) &&
(EndB == NULL || EndB >= StartA)
假设:
从StartA到EndA的日期时间范围,从StartB到EndB的日期时间
DateTime ranges of StartA to EndA and StartB to EndB
抱歉,我很快将以上逻辑放在一起,当任一范围的开始日期和结束日期均为NULL时,这似乎失败了.有关详情,请参见下面的David解决方案.解释清楚的方法.
Sorry I quickly threw the above logic together, which seems to fail when either range's start and end dates are NULL. See David's solution below for a better & well-explained approach.
推荐答案
查看全文