Check if a date range is within a date range

前端 未结 8 2115
爱一瞬间的悲伤
爱一瞬间的悲伤 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:43

    A bit late but I couldn't find this pattern anywhere in the answers/comments.

        if (startDate1 <= endDate2 && startDate2 <= endDate1)
        {
         // Overlaps.
        }
    

提交回复
热议问题