<!--
{
  "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",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation4DateV19IntervalFormatStyleV"
  },
  "title" : "Date.IntervalFormatStyle"
}
-->

# Date.IntervalFormatStyle

A format style that creates string representations of date intervals.

```
struct IntervalFormatStyle
```

## Overview

Use a date interval format style to create user-readable strings in the form of `<start> - <end>` for your app’s interface, where `<start>` and `<end>` are date values that you supply. The format style uses locale and language information, along with custom formatting options, to define the content of the resulting string.

`Date.IntervalFormatStyle` provides a variety of localized presets and configuration options to create user-visible representations of date intervals. When displaying a date interval to a user, use the [`formatted(date:time:)`](/documentation/Foundation/Date/formatted(date:time:)) instance method of `Range<Date>`. Set the date and time styles of the date interval format style separately, according to your particular needs.

For example, to create a date interval string with a full date and no time representation, set the [`Date.IntervalFormatStyle.DateStyle`](/documentation/Foundation/Date/IntervalFormatStyle/DateStyle) to [`complete`](/documentation/Foundation/Date/FormatStyle/DateStyle/complete) and the [`Date.IntervalFormatStyle.TimeStyle`](/documentation/Foundation/Date/IntervalFormatStyle/TimeStyle) to [`omitted`](/documentation/Foundation/Date/FormatStyle/TimeStyle/omitted). The following example creates a formatted interval string with this style:

```swift
if let today = Calendar.current.date(byAdding: .day, value: -120, to: Date()),
    let thirtyDaysBeforeToday = Calendar.current.date(byAdding: .day, value: -30, to: today) {
    // today: June 5, 2023
    // thirtyDaysBeforeToday: May 6, 2023

    // Create a Range<Date>.
    let last30days = thirtyDaysBeforeToday..<today

    let formatted = last30days.formatted(date: .complete, time: .omitted)
    // "Saturday, January 30 – Monday, March 1, 2021"
}
```

You can create string representations of date intervals with various levels of brevity using a variety of preset date and time styles. The following example shows date styles of [`long`](/documentation/Foundation/Date/FormatStyle/DateStyle/long), [`abbreviated`](/documentation/Foundation/Date/FormatStyle/DateStyle/abbreviated), and [`numeric`](/documentation/Foundation/Date/FormatStyle/DateStyle/numeric), and time styles of [`shortened`](/documentation/Foundation/Date/FormatStyle/TimeStyle/shortened), [`standard`](/documentation/Foundation/Date/FormatStyle/TimeStyle/standard), and [`complete`](/documentation/Foundation/Date/FormatStyle/TimeStyle/complete):

```swift
if let today = Calendar.current.date(byAdding: .day, value: -120, to: Date()),
   let thirtyDaysBeforeToday = Calendar.current.date(byAdding: .day, value: -30, to: today) {
   // today: Mar 1, 2021 at 8:01 PM
   // thirtyDaysBeforeToday: Jan 30, 2021 at 8:01 PM

   // Create a Range<Date>.
   let last30days = thirtyDaysBeforeToday..<today

   print(last30days.formatted(date: .long, time: .shortened))
   // January 30, 2021, 8:01 PM – March 1, 2021, 8:01 PM

   print(last30days.formatted(date: .abbreviated, time: .standard))
   // Jan 30, 2021, 8:01:49 PM – Mar 1, 2021, 8:01:49 PM

   print(last30days.formatted(date: .numeric, time: .complete))
   // 1/30/2021, 8:01:49 PM CST – 3/1/2021, 8:01:49 PM CST

   print(last30days.formatted())
   // 1/30/21, 8:01 PM – 3/1/21, 8:01 PM
}
```

The default date style is [`abbreviated`](/documentation/Foundation/Date/FormatStyle/DateStyle/abbreviated) and the default time style is [`shortened`](/documentation/Foundation/Date/FormatStyle/TimeStyle/shortened).

For full customization of the string representation of a date interval, use the [`formatted(_:)`](/documentation/Foundation/Date/formatted(_:)) instance method of `Range<Date>` and provide a [`Date.IntervalFormatStyle`](/documentation/Foundation/Date/IntervalFormatStyle) instance.

You can achieve any customization of date and time representation your app requires by appying a series of convenience modifiers to your format style. The following example applies a series of modifiers to the format style to precisely define the formatting of the year, month, day, hour, minute, and time zone components of the resulting string:

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

    // Create a Range<Date>.
    let weekFromNow = today..<sevenDaysAfterToday
    
    // Call the .formatted method on a Range<Date> and pass in an instance of Date.IntervalFormatStyle.
    weekFromNow.formatted(
        Date.IntervalFormatStyle()
            .year()
            .month(.abbreviated)
            .day()
            .hour(.defaultDigits(amPM: .narrow))
            .weekday(.abbreviated)
    ) //  Wed, Feb 10, 2021, 3 p – Wed, Feb 17, 2021, 3 p
}
```

[`Date.IntervalFormatStyle`](/documentation/Foundation/Date/IntervalFormatStyle) provides a convenient factory variable, `interval`, to shorten the syntax when applying date and time modifiers to customize the format.

```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

    let localeArray = ["en_US", "sv_SE", "en_GB", "th_TH", "fr_BE"]
    for localeID in localeArray {
        // Call the .formatted method on a Range<Date> and pass in an instance of Date.IntervalFormatStyle.
        print(weekBefore.formatted(.interval
                 .day()
                 .month(.wide)
                 .weekday(.short)
                 .hour(.conversationalTwoDigits(amPM: .wide))
                 .locale(Locale(identifier: localeID))))
    }
}
// We, February 3, 3 PM – We, February 10, 3 PM
// on 3 februari 15 – on 10 februari 15
// We 3 February, 15 – We 10 February, 15
// พ. 3 กุมภาพันธ์ 15 – พ. 10 กุมภาพันธ์ 15
// me 3 février, 15 h – me 10 février, 15 h
```

## Topics

### Creating a Date Interval Format Style

[`init(date:time:locale:calendar:timeZone:)`](/documentation/Foundation/Date/IntervalFormatStyle/init(date:time:locale:calendar:timeZone:))

Creates an instance using the provided date, time, locale, calendar, time zone, and capitalization context.

### Specifying Date Interval Format Styles

[`timeZone(_:)`](/documentation/Foundation/Date/IntervalFormatStyle/timeZone(_:))

Modifies the date interval format style to use the specified time zone format.

[`locale(_:)`](/documentation/Foundation/Date/IntervalFormatStyle/locale(_:))

Modifies the date interval format style to use the specified locale.

[`calendar`](/documentation/Foundation/Date/IntervalFormatStyle/calendar)

The calendar for formatting the date interval.

[`locale`](/documentation/Foundation/Date/IntervalFormatStyle/locale)

The locale for formatting the date and time interval components.

[`timeZone`](/documentation/Foundation/Date/IntervalFormatStyle/timeZone)

The time zone for formatting the date interval components.

### Modifying Date Interval Format Styles

[`day()`](/documentation/Foundation/Date/IntervalFormatStyle/day())

Modifies the date interval format style to include the day.

[`hour(_:)`](/documentation/Foundation/Date/IntervalFormatStyle/hour(_:))

Modifies the date interval format style to use the specified hour format style.

[`minute()`](/documentation/Foundation/Date/IntervalFormatStyle/minute())

Modifies the date interval format style to include the minutes.

[`month(_:)`](/documentation/Foundation/Date/IntervalFormatStyle/month(_:))

Modifies the date interval format style to include the month.

[`second()`](/documentation/Foundation/Date/IntervalFormatStyle/second())

Modifies the date interval format style to include the seconds.

[`weekday(_:)`](/documentation/Foundation/Date/IntervalFormatStyle/weekday(_:))

Modifies the date interval format style to include the specified weekday style.

[`year()`](/documentation/Foundation/Date/IntervalFormatStyle/year())

Modifies the date interval format style to include the year.

### Formatting a Date Interval Format Style

[`format(_:)`](/documentation/Foundation/Date/IntervalFormatStyle/format(_:))

Creates a locale-aware string representation from a relative date value.

### Comparing Date Interval Format Styles

[`==(_:_:)`](/documentation/Foundation/Date/==(_:_:))

Returns true if the two `Date` values represent the same point in time.

### Supporting Types

[`Date.IntervalFormatStyle.DateStyle`](/documentation/Foundation/Date/IntervalFormatStyle/DateStyle)

The type that defines date interval styles that vary in length or in their included components.

[`Date.IntervalFormatStyle.Symbol`](/documentation/Foundation/Date/IntervalFormatStyle/Symbol)

The type that supports customizing formatting templates using the date format style’s modifier functions, and constructing fixed-pattern date format strings.

[`Date.IntervalFormatStyle.TimeStyle`](/documentation/Foundation/Date/IntervalFormatStyle/TimeStyle)

The type that defines time styles that vary in length or in their included components.



---

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)