i am making a booking system and i am thinking how am i suppose to know if there is a conflicting time.. i want to add an Error message if the time is conflicting in other event help me please

            Date       Time Start      Time End
DEBUT    September 18    5:00 PM       10:00 PM
Birthday September 18    3:00 PM        7:00 PM

Edited by Shodow: more detail

4 Years
Discussion Span
Last Post by G_Waddell

Where are your Events being Stored? are they on a database?

Anyway the logic for comparing the two events to see if there is a clash is something like this:

Sub CompareEvents (byref Event1Start as datetime, byref Event1End as DateTime, byRef Event2Start as Datetime, ByRef Event2End as Datetime)

    IF (Event1Start < = Event2End) AndAlso (Event1End  = > Event2Start) then
        'Overlap Event2 ends after event1 starts and Starts before Event one ends
    ElseIf (Event2Start < = Event1End) AndAlso (Event2End = > Event1Start) Then
        'Overlap Event 1 ends after Event2 starts and starts before Event2 ends
    End if
End sub
Made it look so easy.

Thanks AndreRet!

If they are on a database then you could run a query to check for conflicts before adding.

sSQL = "SELECT COUNT(*) AS NoOfConflicts From MyEvents" & _ 
    "WHERE ((@EventStart <= EndDate) AND (@EventEnd => Startdate)) " & _ 
    "OR ((StartDate <= @EventEnd) AND (EndDate => @EventStart)"

'Ill Assume you have SQL Server
dim cmd as new sqlCommand
dim conn as new sqlConnection(MyConnectionString)
with cmd
.commandType = CommandType.Text
.CommandText = sSQL
.Connection = conn
.Parameters.AddWithValue("EventStart", EventStartDate)
End With
IF Conn.State <> ConnectionState.Open then
End If
if cmd.ExecuteScalar() >0 then
'There is a conflict
end if
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.