Don’t miss your chance to experience Discovery Summit Europe at our best available rate! Early bird registration through 31 Oct.
Graph Builder Toolbar streamlines interactive graphing. Creates shortcuts on Report and GraphBuilder Helpers toolbars. Download and install the extension.
Selecting all rows in a data table where date/time is between two values in another table
Jul 18, 2025 11:24 AM(2013 views)
Hi,
I have two data tables named, HVAC and Events. I want to match date/times in HVAC based on start time and end times of the Events table and mark the matching rows in HVAC table with 1.
I have script that runs but does not populate the "Matched" column and I am not quite sure why.
Names Default to Here (1);
Clear Symbols();
// Reference both tables
timeEvents = DataTable("Events");
timeHVAC = DataTable("HVAC");
// Get column references
startCol = timeEvents:Round_when_started;
endCol = timeEvents:Round_when_ended;
timeHVACCol = timeHVAC:Round_date;
matchedCol = timeHVAC:Matched;
Batch Interactive( 1 );
// Loop through timeEvents and tag matches
For(i = 1, i <= N Rows(timeEvents), i++,
startTime = startCol[i];
endTime = endCol[i];
// Loop through HVAC and tag matching rows
For(j = 1, j <= N Rows(timeHVAC), j++,
eventTime = timeHVACCol[j];
If(eventTime >= startTime & eventTime <= endTime,
matchedCol[j] = 1;
);
);
);
Batch Interactive( 0 );
// Notify user
New Window("Script Completed",
Text Box("Lucy, I'm home!")
);
If this is how your data looks like (even hours) and the matches are defined like in your script, you should be able to do this with double join/update. Add Matched column to your Events table
and then first join using Round_date and Round_when_started
Then for second join use Round_date and round_when_ended.
And of course you can use something like Jim did demonstrate.
I think you shouldn't need JMP Pro for what I did. I just used Tables > Update (should be available with standard JMP) twice but you could also do it with a single query using Query Builder
SELECT t1.Round_date, t1."Building pressure", t1."Plant Temp", t1."Zone Humdity",
t1."outside air temp", t3.Round_when_ended IS NOT NULL OR t2.Round_when_started IS NOT NULL AS Calc1, t3.Round_when_ended IS NOT NULL OR t2.Round_when_started IS NOT NULL AS "Calc1 2"
FROM HVAC t1
LEFT OUTER JOIN Events t3
ON ( t1.Round_date = t3.Round_when_ended )
LEFT OUTER JOIN Events t2
ON ( t1.Round_date = t2.Round_when_started );
And JMP's query builder script is something like this