day

Day number or name

Description

example

d = day(t) returns the day-of-month numbers for the datetime values in t. The d output contains integer values from 1 to 31, depending on the month and year.

example

d = day(t,dayType) returns the type of day number or name specified by dayType.

The day function returns the day numbers or names of datetime values. To assign day values to datetime array t, use t.Day and modify the Day property.

Examples

collapse all

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

t = [datetime('yesterday');datetime('today');datetime('tomorrow')]
t = 3x1 datetime array
   25-Aug-2019
   26-Aug-2019
   27-Aug-2019

d = day(t)
d = 3×1

    25
    26
    27

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
   16-May-2014

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

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.

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

Value of dayTypeDescription
'dayofmonth'Day-of-month number, from 1 to 28, 29, 30, or 31. The range depends on the month.
'dayofweek'Day-of-week number, from 1 to 7, where day 1 of the week is Sunday.
'dayofyear'Day-of-year number, from 1 to 365 or 366, depending on the year.
'name'Full day names, for example, Sunday. For NaT datetime values, the day name is the empty character vector, ''.
'shortname'Abbreviated day names, for example, Sun. For NaT datetime values, the day name is the empty character vector, ''.

Note

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

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

Introduced in R2014b