weekday

Returns the day of the week for the given date.

Syntax

[d, s] = weekday(date)

[d, s] = weekday(date, format)

Inputs

date
The date as a number (datenum) or as a string. If the date is a string, it must be in a format that datevec can read.
Type: double | string
Dimension: scalar | matrix | cell
format
The format of the output s. The value can be either 'short' or 'long' with 'short' being the default. If format is 'short' then the abbreviated day name is returned. If it is 'long' then the full day name is returned.
Type: string

Outputs

d
The day of the week, [1-7] with 1 being Sunday.
s
The name of the day. Full name or abbreviation depending on the format input.

Examples

Get the day of the week from a date number:

[d, s] = weekday(now)

d = 6
s = Fri

Get the full day name for each date number in a matrix:

[d, s] = weekday(now+[1:6], 'long')
d = [Matrix] 1 x 6
7  1  2  3  4  5
s = 
Saturday 
Sunday   
Monday   
Tuesday  
Wednesday
Thursday 

Get the day of the week from a date string:

[d, s] = weekday('20-Aug-2022')
d = 7
s = Sat

Get the day of the week for each date string in a cell of strings:

[d, s] = weekday({'Aug.04,2022', '20-Sep-2022'})
d = [Matrix] 1 x 2
5  3
s = 
Thu
Tue