<!--
{
  "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/IntervalFormatStyle/year()",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation4DateV19IntervalFormatStyleV4yearAEyF"
  },
  "title" : "year()"
}
-->

# year()

Modifies the date interval format style to include the year.

```
func year() -> Date.IntervalFormatStyle
```

## Return Value

A date interval format style that includes the year.

## Discussion

Use a combination of modifier instance methods to customize the format of the date interval. The following example shows several combinations of year, month, and day components in the date interval:

```swift
if let today = Calendar.current.date(byAdding: .day, value: -140, to: Date()),
   let sevenDaysBeforeToday = Calendar.current.date(byAdding: .day, value: -7, to: today) {

    // Create a Range<Date>.
    let weekBefore = sevenDaysBeforeToday..<today

    print(weekBefore.formatted(.interval))
    print(weekBefore.formatted(.interval.day()))
    print(weekBefore.formatted(.interval.day().month(.defaultDigits)))
    print(weekBefore.formatted(.interval.day().month(.wide).year()))
}
// 2/5/21, 6:37 AM – 2/12/21, 6:37 AM
// 5 – 12
// 2/5 – 2/12
// February 5 – 12, 2021
```

---

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)