Main Content

weekday

Description

DayNumber = weekday(D) returns a number representing the day of the week for each element in D.

example

[DayNumber,DayName] = weekday(D) additionally returns abbreviated English names for the day of the week, in DayName.

example

[DayNumber,DayName] = weekday(D,DayForm) returns the name for the day of the week in the format specified by DayForm, in US English.

[DayNumber,DayName] = weekday(D,language) returns the abbreviated name for the day of the week in the language of the locale specified in language.

example

[DayNumber,DayName] = weekday(D,DayForm,language) returns the name for the day of the week in the specified format and in the language of the specified locale. You can specify DayForm and language in either order.

Examples

collapse all

Determine the day of the week of December 21, 2012.

D = '21-Dec-2012';
[DayNumber,DayName] = weekday(D)
DayNumber = 6
DayName = 
'Fri'

December 21, 2012, falls on a Friday.

Return the full name of the day of the week for a vector of serial date numbers.

D = [734999;735015];
DayForm = 'long';
[DayNumber,DayName] = weekday(D,DayForm)
DayNumber = 2×1

     5
     7

DayName = 2x8 char array
    'Thursday'
    'Saturday'

Return a day name in U.S. English using the language input argument.

D = 728647;
DayForm = 'long';
language = 'en_US';
[DayNumber,DayName] = weekday(D,DayForm,language)
DayNumber = 2
DayName = 
'Monday'

In U.S. English, the name of the day of the week is Monday.

Return day names in the language of the current locale.

language = 'local';
[DayNumber,DayName] = weekday(D,DayForm,language);

The value of DayName depends on the locale. For example, in a French locale, the name of the day of the week is Lundi.

Determine the day of the week for a date specified in the format mmm.dd.yyyy. Call datenum inside of weekday to specify the format of the input text representing a date.

[DayNumber,DayName] = weekday(datenum('Dec.21.2012','mmmm.dd.yyyy'))
DayNumber = 6
DayName = 
'Fri'

Input Arguments

collapse all

Serial date numbers or text representing dates and times. Date numbers can be specified as a vector or matrix. Text can be specified as a character vector, a cell array of character vectors, a string array, or a character array where each row represents a date. If D is a cell array of character vectors or a string array, then it must be 1-by-n or n-by-1.

If D is a character vector, a cell array of character vectors, a string array, or a character array, then the dates can be in one of the following formats.

Date FormatExample
dd-mmm-yyyy01-Mar-2000
mm/dd/yyyy03/01/2000
yyyy-mm-dd2000-03-01

For text representing dates in other formats, first convert the dates to serial date numbers using the datenum function, before passing them to weekday.

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

Format of the output day names, specified as one of the following values.

DayFormFormat of DayName NamesExample
'short'Abbreviated nameMon
'long'Full name Monday

Output language of day names in DayName, specified as one of the following values.

languageDescription
'en_US'US English
'local'Language of the current locale

Output Arguments

collapse all

Value representing the day of the week, returned as an array of integers in the range [1,7], where 1 represents Sunday, and 7 represents Saturday.

  • If input D is a numeric array, then the size of DayNumber is equivalent to the size of D.

  • If input D is a cell array of character vectors, then DayNumber is an m-by-1 vector, where m is equivalent to the length of D.

Name of the day of the week, returned as a character array. The content of DayName depends on DayForm.

  • If DayForm is 'short', then DayName contains an abbreviated name (for example, Tues).

  • If DayForm is 'long', then DayName contains the full name of the weekday (for example, Tuesday).

DayName is m-by-n, where m is the number of dates represented in D.

Extended Capabilities

Version History

Introduced before R2006a

See Also

| |