c# - 检查重叠日期

标签 c# datetime

我有 4 个日期 startDateendDateperiodStartDateperiodEndDate

如果 startDateendDate 表示的时间段与 periodStartDate 表示的时间段重叠,我需要一个方法返回 true code>periodEndDate.

这是 C# 3.5,所以不能使用元组。喜欢建议的链接

我的大脑似乎无法正常工作,请有人帮帮我。

谢谢!

最佳答案

if (startDate<periodStartDate)//start date is older
{

   if (periodStartDate < endDate) //if end date is later than start of period
       return true;
   else return false; //
}
else //period start is older
{
    if (periodEndDate < startDate) //period ended before startdate
         return false;
    else
         return true;
}

只需注意你想要“<”的位置,以及“<=”的位置

编辑(更优雅的解决方案):

if (end1<start2) || (end2<start1) return false
else return true;

关于c# - 检查重叠日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5705275/

相关文章:

c# - 包含组合框窗口窗体的组合框项

c# - 线程安全缓存机制(不是.NET内置缓存) ASPX C#

c# - 日期格式 yyyymmdd 到 yyyy-mm-dd

c# - 比较日期时间,看看是否已经过去一小时

Javascript 将毫秒显示为天 :hours:mins without seconds

c# - Google Pay 通行证

c# - 流利的 NHibernate : mapping child collection with discriminator

MySql:如何将日期从时间戳更新为日期时间

mysql - 查询返回空行之间的日期

python - 当询问 Timestamp 列值是否具有 attr astype 时,Pandas 给出了错误的结果