检查重叠日期 (vb.net)

发布于 2024-08-11 08:47:04 字数 150 浏览 7 评论 0原文

在我正在编写的程序中,我正在创建一些带有开始日期(使用日期选择器)和结束日期(也使用日期选择器)的对象。 现在我需要检查该对象的日期范围是否与数据库中存储的任何其他对象的日期范围重叠。如果是,我无法将其保存在数据库中,但如果不是,我可以。

任何人都知道如何做到这一点?

in a program I'm writing I'm creating some objects with a start date (with a datepicker) and an end date (also with a datepicker).
Now I need to check if this object's date range overlaps with any other object's date range stored in the database. If it does I can't save it in the database but if it doesn't I can.

Anyone has an idea how to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

对你的占有欲 2024-08-18 08:47:04

以下相当于 Garry 的建议

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

Below is equivalent to what Garry suggest

select   count(1)
from     YourTable
where    (@start < End and @end > Start)
漫雪独思 2024-08-18 08:47:04

您有 3 种重叠场景:包含开始、包含结束和环绕范围。这可以用 SQL 来表达,如下所示:

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 */

您实际上如何向数据库发出此查询取决于您当前如何进行数据访问。

You have 3 scenarios for overlapping: contains start, contains end and wraps range. This can be expressed in SQL like this:

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 */

How you actually issue this query to the database depends on how you're doing data access at the moment.

烟火散人牵绊 2024-08-18 08:47:04

最简单的重叠检查是查看新事件是否在另一个事件结束之前开始,并在该事件开始之后结束。如果两个条件都成立,则新事件与旧事件重叠。

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

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

select   *
from     YourTable
where    @start < End and @end > Start
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文