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

# Date.RelativeFormatStyle

A format style that forms locale-aware string representations of a relative date or time.

```
struct RelativeFormatStyle
```

## Overview

Use the strings that the format style produces, such as “1 hour ago”, “in 2 weeks”, “yesterday”, and “tomorrow” as standalone strings. Embedding them in other strings may not be grammatically correct.

Express relative date formats in either [`numeric`](/documentation/Foundation/Date/RelativeFormatStyle/Presentation-swift.struct/numeric) or [`named`](/documentation/Foundation/Date/RelativeFormatStyle/Presentation-swift.struct/named) styles. For example:

```swift
if let past = Calendar.current.date(byAdding: .day, value: -7, to: Date()) {
    var formatStyle = Date.RelativeFormatStyle()
    
    formatStyle.presentation = .numeric
    past.formatted(formatStyle) // "1 week ago"
    
    formatStyle.presentation = .named
    past.formatted(formatStyle) // "last week"
}
```

Use the convenient static factory method [`relative(presentation:unitsStyle:)`](/documentation/Foundation/FormatStyle/relative(presentation:unitsStyle:)) to shorten the syntax when applying presentation and units style modifiers to customize the format. For example:

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

    past.formatted(.relative(presentation: .numeric)) // "in 1 week"
    past.formatted(.relative(presentation: .named)) // "next week"

    past.formatted(.relative(presentation: .named, unitsStyle: .wide)) // "next week"
    past.formatted(.relative(presentation: .named, unitsStyle: .narrow)) // "next wk."
    past.formatted(.relative(presentation: .named, unitsStyle: .abbreviated)) // "next wk."
    past.formatted(.relative(presentation: .named, unitsStyle: .spellOut)) // "next week"
    past.formatted(.relative(presentation: .numeric, unitsStyle: .wide)) // "in 1 week"
    past.formatted(.relative(presentation: .numeric, unitsStyle: .narrow)) // "in 1 wk."
    past.formatted(.relative(presentation: .numeric, unitsStyle: .abbreviated)) // "in 1 wk."
    past.formatted(.relative(presentation: .numeric, unitsStyle: .spellOut)) // "in one week"
}
```

The [`format(_:)`](/documentation/Foundation/Date/FormatStyle/format(_:)) instance method generates a string from the provided relative date. Once you create a style, you can use it to format relative dates multiple times.

The following example applies a format style repeatedly to produce string representations of relative dates:

```swift
if let pastWeek = Calendar.current.date(byAdding: .day, value: -7, to: Date()), 
  let pastDay = Calendar.current.date(byAdding: .day, value: -1, to: Date()) {

    let formatStyle = Date.RelativeFormatStyle(
        presentation: .named,
        unitsStyle: .spellOut,
        locale: Locale(identifier: "en_GB"),
        calendar: Calendar.current,
        capitalizationContext: .beginningOfSentence)
        
    formatStyle.format(pastDay) // "Yesterday"
    formatStyle.format(pastWeek) // "Last week"
}
```

## Topics

### Creating a Relative Date Format Style

[`init(presentation:unitsStyle:locale:calendar:capitalizationContext:)`](/documentation/Foundation/Date/RelativeFormatStyle/init(presentation:unitsStyle:locale:calendar:capitalizationContext:))

Creates a relative date format style with the specified presentation, units, locale, calendar, and capitalization context.

### Modifying a Relative Date Format Style

[`presentation`](/documentation/Foundation/Date/RelativeFormatStyle/presentation-swift.property)

Specifies the style to use when describing a relative date, such as “1 day ago” or “yesterday”.

[`unitsStyle`](/documentation/Foundation/Date/RelativeFormatStyle/unitsStyle-swift.property)

The style to use when formatting the quantity or the name of the unit, such as “1 day ago” or “one day ago”.

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

The calendar to use when formatting relative dates.

[`capitalizationContext`](/documentation/Foundation/Date/RelativeFormatStyle/capitalizationContext)

The capitalization context to use when formatting the relative dates.

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

The locale to use when formatting the relative date.

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

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

### Formatting a Relative Date

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

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

### Comparing Relative Date Format Styles

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

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

### Supporting Types

[`Date.RelativeFormatStyle.Presentation`](/documentation/Foundation/Date/RelativeFormatStyle/Presentation-swift.struct)

A type that represents the style to use when formatting relative dates, such as “1 week ago” or “last week”.

[`Date.RelativeFormatStyle.UnitsStyle`](/documentation/Foundation/Date/RelativeFormatStyle/UnitsStyle-swift.struct)

A type that represents the style to use when formatting the units of relative dates.



---

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)