isbetween

Determine elements within date and time interval

Description

example

tf = isbetween(t,tlower,tupper) returns an array containing logical 1 (true) where the corresponding element of t is a datetime or duration value that lies within the closed interval specified by the corresponding elements of tlower and tupper. The output tf indicates which elements of t satisfy:

tlower <= t <= tupper

The sizes of t, tlower, and tupper must be the same or be compatible. If the sizes of the input arrays are compatible, then the arrays implicitly expand to match each other. For example, if one of t, tlower, or tupper is a scalar, then the scalar is compared to each element of the other arrays. Also, vectors with different orientations (row vectors and column vectors) implicitly expand to form a matrix.

Examples

collapse all

Define a lower bound and an upper bound for dates.

tlower = datetime(2014,05,16)
tlower = datetime
   16-May-2014

tupper = '23-May-2014'
tupper = 
'23-May-2014'

tlower and tupper can be datetime arrays or character vectors. Here, tlower is a datetime array and tupper is a single character vector.

Create an array of datetime values and determine if each datetime lies within the interval bounded by tlower and tupper.

t = tlower + caldays(2:2:10)
t = 1x5 datetime
   18-May-2014   20-May-2014   22-May-2014   24-May-2014   26-May-2014

tf = isbetween(t,tlower,tupper)
tf = 1x5 logical array

   1   1   1   0   0

Input Arguments

collapse all

Input date and time, specified as a datetime array, duration array, character vector, cell array of character vectors, or string array. Character vectors and strings must be formatted to represent dates and times.

Lower bound of date and time interval, specified as a datetime array, duration array, character vector, cell array of character vectors, or string array. Character vectors and strings must be formatted to represent dates and times.

Upper bound of date and time interval, specified as a datetime array, duration array, character vector, cell array of character vectors, or string array. Character vectors and strings must be formatted to represent dates and times.

Compatibility Considerations

expand all

Behavior changed in R2020b

Extended Capabilities

See Also

| | | |

Introduced in R2014b