Main Content


Day number or name of input date and time



d = day(t) returns the day-of-month numbers for each date and time specified in t.

The d output is a double array containing integer values from 1 to 31, depending on the month and year. To assign day values to datetime array t, use t.Day and modify the Day property.


d = day(t,dayType) returns the type of day number or name of datetime array t, specified as either "dayofmonth", "dayofweek", "dayofyear", "name", or "shortname".


collapse all

Extract the day of month numbers from an array of dates.

t = [datetime('yesterday');datetime('today');datetime('tomorrow')]
t = 3x1 datetime

d = day(t)
d = 3×1


Determine the day of the week for an arbitrary date, by specifying 'name' as the second input to the day function.

t = datetime(2014,05,16)
t = datetime

d = day(t,'name')
d = 1x1 cell array

Alternatively, specify 'dayofweek' to return the day of the week as a number.

d = day(t,'dayofweek')
d = 6

Input Arguments

collapse all

Input date and time, specified as a datetime array.

To support existing code that previously required Financial Toolbox™, day also accepts serial date numbers and text as inputs, but they are not recommended. For more information, see Version History.

Type of day values, specified as a value in the table.

Value of dayType


'dayofmonth' (default)

Day-of-month number, from 1 to 28, 29, 30, or 31. The range depends on the month.


Day-of-week number, from 1 to 7, where day 1 of the week is Sunday.

'iso-dayofweek' (since R2023a)

Day-of-week number, from 1 to 7, according to the ISO 8601 standard, where day 1 of the week is Monday.


Day-of-year number, from 1 to 365 or 366, depending on the year.


Full day names, for example, Sunday. For NaT datetime values, the day name is the empty character vector, ''.


Abbreviated day names, for example, Sun. For NaT datetime values, the day name is the empty character vector, ''.


day returns day names in the language specified by the Locale option in the Datetime format section of the Preferences window. To change the default datetime locale, see Set Command Window Preferences.

This argument is valid only when t is a datetime array.

Output Arguments

collapse all

Day number or name, returned as a numeric array of integers of type double, or a cell array of character vectors. d is the same size as t.

Extended Capabilities

Version History

Introduced in R2014b

expand all