While working in SQL server, a co-worker and I were trying to figure out how to tell if two time spans intersect in any way. We thought that the best way to do this would be to check for the opposite since there would be alot less check in those instances. Check it out!
if (@Beg1D <= @End1D and @Beg2D <= @End2D)
if (@Beg2D > @End1D or @Beg1D > @End2D)
Set @TimeSpansDoIntersect = 0
else
Set @TimeSpansDoIntersect = 1
else
Set @TimeSpansDoIntersect = null
No comments:
Post a Comment