Weekday
Standard library enum · Returned by Date.weekday
A Weekday is a day of the week. A Date or a DateTime gives its
weekday with weekday, and the seven values are written with the type’s name in front, as for any
enum:
const day = Date(2026, 9, 25).weekdayprint(day)print(day == Weekday.friday)FridaytrueA weekday prints as its capitalized English name, which is how it appears when put into text.
The values
Section titled “The values”| Value | Prints as |
|---|---|
Weekday.monday |
Monday |
Weekday.tuesday |
Tuesday |
Weekday.wednesday |
Wednesday |
Weekday.thursday |
Thursday |
Weekday.friday |
Friday |
Weekday.saturday |
Saturday |
Weekday.sunday |
Sunday |
Comparing weekdays
Section titled “Comparing weekdays”Weekdays can be compared with == and used as dictionary keys, but they have no order and no
number. A week is a cycle, and whether it starts on Sunday or Monday, or counts from 0 or 1, differs
between countries and between programs. So Weekday.monday < Weekday.tuesday is an error, rather
than a quiet choice of one convention. The values are listed Monday first, as in the international
date standard, only to make them easy to read.
To ask about groups of days, use a case, which also makes sure every day
is handled:
const day = Date(2026, 9, 26).weekdayconst kind = case day { when Weekday.saturday, Weekday.sunday then "weekend" else then "weekday"}print(kind)weekend