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

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
commented: Made it look so easy. +12

yup they are on database

So did Waddell's code work for you? Nice code by the way...

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