Navigation

Operators and Keywords

Function List:

C++ API

: [n, s] = weekday (d)
: [n, s] = weekday (d, format)

Return the day of the week as a number in n and as a string in s.

The days of the week are numbered 1–7 with the first day being Sunday.

d is a serial date number or a date string.

If the string format is not present or is equal to "short" then s will contain the abbreviated name of the weekday. If format is "long" then s will contain the full name.

Table of return values based on format:

n"short""long"
1SunSunday
2MonMonday
3TueTuesday
4WedWednesday
5ThuThursday
6FriFriday
7SatSaturday

See also: eomday, is_leap_year, calendar, datenum, datevec.

Demonstration 1

The following code

 ## Current weekday
 [n, s] = weekday (now ())

Produces the following output

n =  2
s = Mon

Demonstration 2

The following code

 ## Weekday from datenum input
 [n, s] = weekday (728647)

Produces the following output

n =  2
s = Mon

Demonstration 3

The following code

 ## Weekday of new millennium from datestr input
 [n, s] = weekday ("1-Jan-2000")

Produces the following output

n =  7
s = Sat

Package: octave