%% Dates Within Open and Half-Open Intervals
% Specify upper and lower bounds for an interval testing dates.

tlower = datetime(2021,5,16)
tupper = datetime(2021,5,23)

%
% Create an array of datetime values, with the first element equal to tlower.

t = tlower + caldays(0:2:8)

%
% Determine which dates occur within the open interval, tlower < t & t < tupper.

tf = isbetween(t,tlower,tupper,'open')

%
% To display the dates within the open interval, index into t using tf as logical indices.

t(tf)

%
% Determine which dates occur within the half-open interval, tlower <= t & t < tupper. Display the dates.

tf = isbetween(t,tlower,tupper,'openright');
t(tf)

% Copyright 2021 The MathWorks, Inc.