ExtensionMethod.NET Home of 816 C#, Visual Basic, F# and Javascript extension methods

Intersects

Returns true if two date ranges intersect.

Source

public static class DateTimeExtensions
{
	public static bool Intersects(this DateTime startDate, DateTime endDate, DateTime intersectingStartDate, DateTime intersectingEndDate)
	{
		return (intersectingEndDate >= startDate && intersectingStartDate <= endDate);
	}
}

Example

bool eventsInterect = eventXStartDate.Intersects(eventXEndDate, eventYStartDate, eventYEndDate);

Author: Walter Quesada

Submitted on: 24 mei 2012

Language: C#

Type: System.DateTime

Views: 8247