Check Matching Dates (vb.net)

in the program I am writing, I create some objects with a start date (with a dumper) and an end date (also with a dumper). Now I need to check if this date range of the object matches any other date range of the object stored in the database. If so, I cannot save it to the database, but if it is not, I can.

Does anyone have an idea how to do this?

+3
source share
3 answers

Below is the equivalent of what Harry offers [/ p>

select   count(1)
from     YourTable
where    (@start < End and @end > Start)
+9
source

You have 3 scripts for overlapping: contains start, contains the range of end and wraps. This can be expressed in SQL as follows:

select   count(1)
from     YourTable
where    (@start >= Start and @start <= End) /* contains start */
or       (@end >= Start and @end <= End) /* contains end */
or       (@start < Start and @end > End) /* wraps range */

, , .

+5

The simplest match check is to see if a new event was fired before the end of another event and ended after it started. If both conditions are true, the new event overlaps with the old.

select   *
from     YourTable
where    @start < End and @end > Start
+3
source

Source: https://habr.com/ru/post/1722910/


All Articles