isnat

Marks datetime elements that are NaT (not a time).

Category: Language Fundamentals > Data Types

Syntax

tf = isnat(t)

Returns a logical array that is true where the datetime array t holds NaT.

Description

NaT is to datetime what NaN is to numbers: it stands for a missing or invalid date, and it never compares equal to any date. Use isnat instead of == to find it.

Input arguments

t
datetime array.

Output arguments

tf
Logical array the same size as t.

Example

Finding missing dates

t = [datetime(2024,1,1) NaT datetime(2024,3,1)];
isnat(t)
t(~isnat(t))
Output
ans = 1×3 logical array

   0   1   0
ans = 1×2 datetime array

   01-Jan-2024   01-Mar-2024

See also

NaT datetime isnan ismissing