Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6788887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:32:18+00:00 2026-05-26T17:32:18+00:00

I have several records in a database that have Start and End Dates 09/15/2011

  • 0

I have several records in a database that have Start and End Dates

09/15/2011 - 09/30/2011
10/15/2011 - 10/22/2011
11/01/2011 - 11/15/2011

When user stores a record, I need to make sure dates don’t overlap.
My simple code checks date ranges within a specific record (e.g. user enters 9/16/2011 or 10/21/2011, I throw an exception.)

But, on the slim chance a user gets creative (e.g. 10/14/2011 – 10/23/2011 or even 10/14/2011 to 11/16/2011), now they have circumvented my check.

BTW, the user could enter 10/14/2011 to 10/23/2011 if they were editing the record that contained values 10/15/2011 – 10/22/2011.

So, I’m trying to solve this riddle with a linq query. However, what I have isn’t working exactly right.


UPDATE Nevermind about code not working. While trying to provide an example to expand on Miika’s repsonse, I found my answer. So, giving credit to Miika for pointing me in the right direction and posting my working code below:

Here’s my code:

        Private Sub CheckForOverlap(myMonth As Messages.MyMonth)


                        Dim am As New MyMonth()
                        Dim amCollection As Messages.MyMonthCollection
                        Dim overlappingMyMonthDate As Boolean = False
                        Dim sErrorMsg As String = ""

'...non-applicable code omitted

    Dim query = From s In amCollection _
                                 Let s1 As MyMonth = CType(s, MyMonth) _
                                 Where s1.AttendanceMonthID <> attendanceMonth.AttendanceMonthID And _
                                 (CDate(attendanceMonth.StartDate) < CDate(s1.StartDate) And CDate(attendanceMonth.EndDate) > CDate(s1.EndDate)) _
                                 Select s1

                If query.Count > 0 Then
                    sErrorMsg = "Dates entered surround another entry"
                End If

                        If overlappingMyMonthDate Then
                            Throw New Exception(sErrorMsg)
                        End If

                    End Sub


                End Class

It all came down a LINQ query.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:32:18+00:00Added an answer on May 26, 2026 at 5:32 pm

    Do you need to do it in code or would SQL be an option? If the data is in a database, you could use the following query to check for overlaps.

    SELECT COUNT(*)
    FROM Table1
    WHERE Table1.StartDate < 'endCheckDate'
        AND Table1.EndDate > 'startCheckDate'
    

    This will return a count of the number of overlaps found. ‘endCheckDate’ and ‘startCheckDate’ are your new query values (in date format). If your data is in a object collection in memory, then you could use LINQ. If you need help with a LINQ statement, let me know.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a huge database that has several tables that hold several million records.
I have a mysql table that have several records linked to one particular tag.
I have a small database that I need help designing. I have a VB.NET
I have the following database design question: I have a record that contains the
I have several models whose records AND associations can have two states that must
I have several web sequential pages which will modify a record and its child
I have a multithreaded process which inserts several records into a single table. The
I have a SQL Server 2008 database. This database has a stored procedure that
Greetings, stack overflow In my database, I already have one table, 'contacts' that contains
I have a series of large, flat text files that I need to parse

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.