%% Determine if Dates Occur Within Interval
% Specify a lower bound and an upper bound for dates.

tlower = datetime(2021,05,16)

%

tupper = "2021-05-23"

% tlower and tupper can be datetime arrays, duration arrays, strings, or character vectors. Here, tlower is a datetime array and tupper is a string scalar.
%
% Create an array of datetime values. You can start with one datetime value, tlower, and add an array of calendar days to it by using the caldays function. The result is an array of datetime values, spaced two days apart.

t = tlower + caldays(2:2:10)

%
% Determine which datetime values lie within the closed interval bounded by tlower and tupper.

tf = isbetween(t,tlower,tupper)

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

t(tf)

% Copyright 2012-2021 The MathWorks, Inc.