Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

weekday

Syntax

  • DayNumber = weekday(D)
  • [DayNumber,DayName] = weekday(D)
    example
  • [DayNumber,DayName] = weekday(D,DayForm)
    example
  • [DayNumber,DayName] = weekday(D,language)
  • [DayNumber,DayName] = weekday(D,DayForm,language)
    example

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

Return Day of Week of Date String

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 Full Day Names of Multiple Date Numbers

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 =

     5
     7


DayName =

Thursday
Saturday

Return Full Day Names in Local Language

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.

Return Day of Week of Date String in Custom Format

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

D — Serial date numbers or text representing dates and timesvector | matrix | character vector | cell array of character vectors | character array

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, or a character array where each row represents a date. If D is a cell array of character vectors, it must be 1-by-n or n-by-1.

If D is a character vector, a cell array of character vectors, or a character array, 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

DayForm — Format of output day names'short' (default) | 'long'

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

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

language — Output language of day names'en_US' (default) | 'local'

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

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

Output Arguments

collapse all

DayNumber — Value representing day of weekarray of integers in the range [1,7]

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.

DayName — Name of day of weekcharacter array

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.

See Also

| |

Introduced before R2006a

Was this topic helpful?