NaT - Not-a-Time - MATLAB (original) (raw)

Syntax

Description

NaT is the representation for Not-a-Time, a value that can be stored in a datetime array to indicate an unknown or missing datetime value.

The datetime function creates a NaT value automatically when it cannot convert text to a datetime value, or for elements in a datetime array where the Year,Month, Day, Hour,Minute, or Second properties are set toNaN. You also can assign missing values to elements of an existing datetime array. Use the NaT function to create a newdatetime array containing only NaT values.

NaT returns a scalar Not-a-Time (NaT) datetime value.

example

t = NaT([n](#buv322t-1-n)) returns an n-by-n matrix of NaT values.

t = NaT([sz1,...,szN](#buv322t-1-sz1szN)) returns a sz1-by-...-by-szN array of NaT values where sz1,...,szN indicates the size of each dimension. For example, NaT(3,4) returns a 3-by-4 array of NaT values.

t = NaT([sz](#buv322t-1-sz)) returns an array of NaT values where the size vector, sz, defines size(t). For example, NaT([3,4]) returns a 3-by-4 array of NaT values.

t = NaT(___,'Format',[fmt](#buv322t-1-fmt)) returns a datetime array with the specified display format. Use this syntax to initialize a datetime array. Not-a-Time values always display as NaT, but non-NaT values assigned to the array will display using the specified format.

example

t = NaT(___,'TimeZone',[tz](#buv322t-1-tz)) returns an array of NaT values in the time zone specified by tz.

Examples

collapse all

Create a 3-by-3 matrix of NaT values.

t = 3×3 datetime NaT NaT NaT NaT NaT NaT NaT NaT NaT

Create a 2-by-3 array of NaT values and specify a date format.

t = NaT(2,3,'Format','dd/MM/yyyy')

t = 2×3 datetime NaT NaT NaT NaT NaT NaT

Assign a datetime value to an element of t.

t(1,2) = datetime('today')

t = 2×3 datetime NaT 01/02/2025 NaT
NaT NaT NaT

Input Arguments

collapse all

Size of square matrix, specified as an integer.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Size of each dimension, specified as separate arguments of integer values.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Size of each dimension, specified as a row vector of integer values. Each element of this vector indicates the size of the corresponding dimension:

Example: sz = [2,3,4] creates a 2-by-3-by-4 array.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Date format, specified as a character vector or string scalar. Use the lettersA-Z and a-z to define the format. For a complete list of valid letter identifiers, see the Format property for datetime arrays.

Alternatively, use one of the following character vectors to specify a default format.

Value of fmt Description
'default' Use the default display format.
'defaultdate' Use the default display format for datetime values created without time components.

Example: 'yyyy MMM dd'

Data Types: char | string

Time zone region, specified as a character vector or string scalar.

The value of tz can be:

This table lists some common names of time zone regions from the IANA Time Zone Database.

Value of TimeZone UTC Offset UTC DST Offset
'Africa/Johannesburg' +02:00 +02:00
'America/Chicago' −06:00 −05:00
'America/Denver' −07:00 −06:00
'America/Los_Angeles' −08:00 −07:00
'America/New_York' −05:00 −04:00
'America/Sao_Paulo' −03:00 −02:00
'Asia/Hong_Kong' +08:00 +08:00
'Asia/Kolkata' +05:30 +05:30
'Asia/Tokyo' +09:00 +09:00
'Australia/Sydney' +10:00 +11:00
'Europe/London' +00:00 +01:00
'Europe/Zurich' +01:00 +02:00

Data Types: char | string

Extended Capabilities

Version History

Introduced in R2015b