Get day of week using NSDate
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
To get the day of the week from an NSDate, you do not ask the date directly. NSDate only represents a moment in time. The weekday comes from interpreting that moment through a calendar, a time zone, and sometimes a locale.
Use Calendar to extract the weekday
In modern Swift, NSDate bridges to Date, and Calendar does the real work. The numeric weekday can be read with .weekday:
For the Gregorian calendar used in most iOS apps, the weekday values are usually:
- '
1for Sunday' - '
2for Monday' - through
7for Saturday
That numbering is easy to forget, so it is worth documenting anywhere the value is persisted or sent over an API.
Getting the weekday name
If you need "Monday" instead of 2, use DateFormatter. This respects the selected locale:
"EEEE" gives the full weekday name. If you want a short form such as "Mon", use "EEE" instead.
Time zone matters more than many people expect
The same absolute timestamp can be one weekday in Toronto and another in Tokyo. If the app logic depends on a specific business time zone, set it explicitly instead of trusting device defaults.
This is especially important for scheduling apps, billing cutoffs, and systems that group data by local day.
Objective-C version
If your codebase is still Objective-C-heavy, the same idea applies:
The API changes slightly, but the concept is identical: date plus calendar produces weekday.
When you need stable weekday labels
If the app uses weekday names for display, avoid hard-coding English names unless that is a product requirement. DateFormatter can localize names correctly, and Calendar exposes weekday symbol arrays when you want the names associated with the active calendar.
This is safer for apps that support multiple regions because "Monday" is not just a translation problem. The first day of the week, the calendar system, and user expectations can all vary by locale.
NSDate versus Date
If you see older documentation using NSDate, do not worry. In Swift, Date is the value-type bridge around the same Foundation concept. The real source of confusion is usually not NSDate itself, but mixing up:
- absolute time
- calendar interpretation
- locale formatting
- time zone conversion
Once those roles are clear, weekday extraction becomes straightforward.
Common Pitfalls
- Expecting
NSDatealone to know the weekday without a calendar. - Forgetting that
.weekdaynumbering depends on the calendar convention and is not always Monday-first. - Using the device time zone when business logic needs a fixed time zone.
- Using a localized formatter for internal logic, then getting different names on different devices.
- Treating
DateandNSDateas separate time models when they are bridged representations of the same value.
Summary
- Use
Calendar.component(.weekday, from:)to get the numeric weekday. - Use
DateFormatterwith"EEEE"or"EEE"when you need a weekday name. - Set calendar and time zone explicitly when correctness matters.
- Remember that
NSDateis just a timestamp; the weekday comes from calendar interpretation. - Prefer modern Swift
Date, but the same approach works with bridgedNSDatevalues.

