Note that there are some explanatory texts on larger screens.

plurals
  1. POComparing dates for overlap - not avoiding
    primarykey
    data
    text
    <p>I'm working on a timetabling piece of code. I am using a system of university modules and events associated to those modules, ie </p> <p>Module CSC3039 Event1 - Lecture Event2 - Lecture Event3 - Practial etc</p> <p>I need to check the times of each event in the module against each other and compare for clashes. The clashes do not need to be rectified, just highlighted. The table I will use is <code>Events</code> containing <code>Event_ID (PK), Module_code (FK), Start_Date_Time, End_Date_Time</code> plus other fields that don't matter here. I have figured out that I need to implement a <code>For Each</code> statement, ultimately resulting in an if statement such as:</p> <p>if (startTime1 &lt;= endTime2 or endTime1 >= startTime2) CLASH</p> <p>My problem is trying to figure out the actual for loop here. I don't know what to write to declare my start times and end times. I presume it is a case of taking event1 and getting its start and end and then checking if event 2, 3 or 4 fit the above if statement. I'm trying to get this but could really use some guidance.</p> <p>EDIT... Based on suggestions below I have implemented the following code:</p> <pre><code> 'return all relevant tables from the Modules database, based on the module code entered by the user. Dim eventTime = (From mods In db.Modules Join evnt In db.Events On mods.Module_code Equals evnt.Module_code Join rm In db.Rooms On rm.Room_ID Equals evnt.Room_ID Join build In db.Buildings On build.Building_code Equals rm.Building_code Where ((mods.Module_code = initialModCode) And (evnt.Room_ID = rm.Room_ID)) Select evnt.Event_ID, evnt.Module_code, evnt.Event_type, evnt.Start_Date_Time, evnt.End_Date_Time, build.Building_code, rm.Room_Number) 'use the gridview to display the result returned by the above query gdvEventsTable.DataSource = eventTime gdvEventsTable.DataBind() Dim listClashes As New List(Of Array) For i As Integer = 0 To eventTime.Count - 1 For j As Integer = i + 1 To eventTime.Count - 1 If (eventTime.ToList(i).Start_Date_Time &lt; eventTime.ToList(j).End_Date_Time) And (eventTime.ToList(i).End_Date_Time &gt; eventTime.ToList(j).Start_Date_Time) Then MsgBox("Clash", MsgBoxStyle.MsgBoxSetForeground, "") listClashes.Add(eventTime) Else MsgBox("No Clash", MsgBoxStyle.MsgBoxSetForeground, "") End If Next Next </code></pre> <p>When trying to add an event to my array list I have noticed, in debug, that no events are sent to the list.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload