day

Day of the month of each datetime value.

Category: Language Fundamentals > Data Types

Syntax

d = day(t)

Returns the day of the month, from 1 to 31.

Description

day(t) is the same as t.Day. It gives the number of the day inside the month, not inside the year or week. For the other parts of a date use month, year, hour, minute and second, or the Year, Month properties of the datetime.

The result is a plain double array, so it can be used directly in comparisons and indexing.

Input arguments

t
datetime array.

Output arguments

d
Numeric array with the size of t.

Example

Days of a range

t = datetime(2020,5,17):datetime(2020,5,19);
day(t)
day(datetime(2020,2,29)) == 29
Output
ans = 1×3

    17    18    19
ans = logical
   1

Notes

Only the one-argument form is implemented: the optional second argument ('dayofyear', 'dayofweek', 'name') is ignored and the day of the month is returned. day does not accept duration or calendarDuration input.

See also

month year datetime weekday dateshift