---
title: Date.IntervalFormatStyle
framework: foundation
role: symbol
role_heading: Structure
path: foundation/date/intervalformatstyle
---

# Date.IntervalFormatStyle

A format style that creates string representations of date intervals.

## Declaration

```swift
struct IntervalFormatStyle
```

## Overview

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:) 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 to complete and the Date.IntervalFormatStyle.TimeStyle to omitted. The following example creates a formatted interval string with this style: 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, abbreviated, and numeric, and time styles of shortened, standard, and complete: 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 and the default time style is shortened. For full customization of the string representation of a date interval, use the formatted(_:) instance method of Range<Date> and provide a 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: 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 provides a convenient factory variable, interval, to shorten the syntax when applying date and time modifiers to customize the format. 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:)](foundation/date/intervalformatstyle/init(date:time:locale:calendar:timezone:).md)

### Specifying Date Interval Format Styles

- [timeZone(_:)](foundation/date/intervalformatstyle/timezone(_:).md)
- [locale(_:)](foundation/date/intervalformatstyle/locale(_:).md)
- [calendar](foundation/date/intervalformatstyle/calendar.md)
- [locale](foundation/date/intervalformatstyle/locale.md)
- [timeZone](foundation/date/intervalformatstyle/timezone.md)

### Modifying Date Interval Format Styles

- [day()](foundation/date/intervalformatstyle/day().md)
- [hour(_:)](foundation/date/intervalformatstyle/hour(_:).md)
- [minute()](foundation/date/intervalformatstyle/minute().md)
- [month(_:)](foundation/date/intervalformatstyle/month(_:).md)
- [second()](foundation/date/intervalformatstyle/second().md)
- [weekday(_:)](foundation/date/intervalformatstyle/weekday(_:).md)
- [year()](foundation/date/intervalformatstyle/year().md)

### Formatting a Date Interval Format Style

- [format(_:)](foundation/date/intervalformatstyle/format(_:).md)

### Comparing Date Interval Format Styles

- [==(_:_:)](foundation/date/==(_:_:).md)

### Supporting Types

- [Date.IntervalFormatStyle.DateStyle](foundation/date/intervalformatstyle/datestyle.md)
- [Date.IntervalFormatStyle.Symbol](foundation/date/intervalformatstyle/symbol.md)
- [Date.IntervalFormatStyle.TimeStyle](foundation/date/intervalformatstyle/timestyle.md)

## Relationships

### Conforms To

- [Copyable](swift/copyable.md)
- [Decodable](swift/decodable.md)
- [Encodable](swift/encodable.md)
- [Equatable](swift/equatable.md)
- [Escapable](swift/escapable.md)
- [FormatStyle](foundation/formatstyle.md)
- [Hashable](swift/hashable.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Applying date and time styles

- [dateTime](foundation/formatstyle/datetime.md)
- [Date.FormatStyle](foundation/date/formatstyle.md)
- [Date.ISO8601FormatStyle](foundation/date/iso8601formatstyle.md)
- [verbatim(_:locale:timeZone:calendar:)](foundation/formatstyle/verbatim(_:locale:timezone:calendar:).md)
- [Date.VerbatimFormatStyle](foundation/date/verbatimformatstyle.md)
- [interval](foundation/formatstyle/interval.md)
- [relative(presentation:unitsStyle:)](foundation/formatstyle/relative(presentation:unitsstyle:).md)
- [Date.RelativeFormatStyle](foundation/date/relativeformatstyle.md)
- [components(style:fields:)](foundation/formatstyle/components(style:fields:).md)
- [Date.ComponentsFormatStyle](foundation/date/componentsformatstyle.md)
