Check if a date range is within a date range

前端 未结 8 2121
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-09 06:01

I have the following class:

public class Membership
{
    public DateTime StartDate { get; set; }
    public DateTime? EndDate { get; set; } // If null then          


        
8条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-09 06:22

    A condition like this should do the trick:

    newItem.StartDate <= range.EndDate && newItem.EndDate.HasValue && newItem.EndDate >= range.StartDate
    

提交回复
热议问题