检查重叠日期 (vb.net)
在我正在编写的程序中,我正在创建一些带有开始日期(使用日期选择器)和结束日期(也使用日期选择器)的对象。 现在我需要检查该对象的日期范围是否与数据库中存储的任何其他对象的日期范围重叠。如果是,我无法将其保存在数据库中,但如果不是,我可以。
任何人都知道如何做到这一点?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
以下相当于 Garry 的建议
Below is equivalent to what Garry suggest
您有 3 种重叠场景:包含开始、包含结束和环绕范围。这可以用 SQL 来表达,如下所示:
您实际上如何向数据库发出此查询取决于您当前如何进行数据访问。
You have 3 scenarios for overlapping: contains start, contains end and wraps range. This can be expressed in SQL like this:
How you actually issue this query to the database depends on how you're doing data access at the moment.
最简单的重叠检查是查看新事件是否在另一个事件结束之前开始,并在该事件开始之后结束。如果两个条件都成立,则新事件与旧事件重叠。
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.