Quantcast

Documentation Center

  • Trial Software
  • Product Updates

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

expand all

Return Day of Week of a 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 day names 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)
DayNumber =

     2


DayName =

Lundi

In a French locale, the name of the day of the week is Lundi.

Return Day of Week of a 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 date string.

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

     6


DayName =

Fri

Input Arguments

expand all

D — Serial date numbers or date stringsvector | matrix | string | cell array of strings | character array

Serial date numbers or date strings. Date numbers can be specified as a vector or matrix. Date strings can be specified as a single string, a cell array of strings, or a character array. If D is a cell array of strings, it must be 1-by-n or n-by-1.

If D is a single date string, a cell array of date strings, or a character array of date strings, the date strings can be in one of the following formats.

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

For date strings in other formats, first convert them 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 strings.

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 strings.

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

Output Arguments

expand 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 strings, 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 serial date numbers or date strings in D.

See Also

| |

Was this topic helpful?