<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 8.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/Date/FormatStyle/dayOfYear(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation4DateV11FormatStyleV9dayOfYearyA2E6SymbolV03DayfG0VF"
  },
  "title" : "dayOfYear(_:)"
}
-->

# dayOfYear(_:)

Modifies the date format style to use the specified day of the year format style.

```
func dayOfYear(_ format: Date.FormatStyle.Symbol.DayOfYear = .defaultDigits) -> Date.FormatStyle
```

## Parameters

`format`

The day of the year format style applied to the date format style.

## Return Value

A date format style modified to include the specified day of the year style.

## Discussion

Values of [`Date.FormatStyle.Symbol.DayOfYear`](/documentation/Foundation/Date/FormatStyle/Symbol/DayOfYear) are [`defaultDigits`](/documentation/Foundation/Date/FormatStyle/Symbol/DayOfYear/defaultDigits), [`threeDigits`](/documentation/Foundation/Date/FormatStyle/Symbol/DayOfYear/threeDigits), and [`twoDigits`](/documentation/Foundation/Date/FormatStyle/Symbol/DayOfYear/twoDigits).

This example shows a variety of [`Date.FormatStyle.Symbol.DayOfYear`](/documentation/Foundation/Date/FormatStyle/Symbol/DayOfYear) formats applied to a date:

```swift
let meetingDate = Date() // Feb 9, 2021 at 3:00 PM
meetingDate.formatted(Date.FormatStyle().dayOfYear(.defaultDigits)) // 40
meetingDate.formatted(Date.FormatStyle().dayOfYear(.twoDigits)) // 40
meetingDate.formatted(Date.FormatStyle().dayOfYear(.threeDigits)) // 040
meetingDate.formatted(Date.FormatStyle().dayOfYear()) // 40
```

If you don’t provide a format, the [`defaultDigits`](/documentation/Foundation/Date/FormatStyle/Symbol/DayOfYear/defaultDigits) static variable is the default format.

For more information about formatting dates, see [`Date.FormatStyle`](/documentation/Foundation/Date/FormatStyle).

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)