---
title: Date.RelativeFormatStyle
framework: foundation
role: symbol
role_heading: Structure
path: foundation/date/relativeformatstyle
---

# Date.RelativeFormatStyle

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

## Declaration

```swift
struct RelativeFormatStyle
```

## Overview

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 or named styles. For example: 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:) to shorten the syntax when applying presentation and units style modifiers to customize the format. For example: 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(_:) 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: 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:)](foundation/date/relativeformatstyle/init(presentation:unitsstyle:locale:calendar:capitalizationcontext:).md)

### Modifying a Relative Date Format Style

- [presentation](foundation/date/relativeformatstyle/presentation-swift.property.md)
- [unitsStyle](foundation/date/relativeformatstyle/unitsstyle-swift.property.md)
- [calendar](foundation/date/relativeformatstyle/calendar.md)
- [capitalizationContext](foundation/date/relativeformatstyle/capitalizationcontext.md)
- [locale](foundation/date/relativeformatstyle/locale.md)
- [locale(_:)](foundation/date/relativeformatstyle/locale(_:).md)

### Formatting a Relative Date

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

### Comparing Relative Date Format Styles

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

### Supporting Types

- [Date.RelativeFormatStyle.Presentation](foundation/date/relativeformatstyle/presentation-swift.struct.md)
- [Date.RelativeFormatStyle.UnitsStyle](foundation/date/relativeformatstyle/unitsstyle-swift.struct.md)

### Initializers

- [init(allowedFields:presentation:unitsStyle:locale:calendar:capitalizationContext:)](foundation/date/relativeformatstyle/init(allowedfields:presentation:unitsstyle:locale:calendar:capitalizationcontext:).md)

### Instance Properties

- [allowedFields](foundation/date/relativeformatstyle/allowedfields.md)

### Type Aliases

- [Date.RelativeFormatStyle.Field](foundation/date/relativeformatstyle/field.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)
- [Date.IntervalFormatStyle](foundation/date/intervalformatstyle.md)
- [relative(presentation:unitsStyle:)](foundation/formatstyle/relative(presentation:unitsstyle:).md)
- [components(style:fields:)](foundation/formatstyle/components(style:fields:).md)
- [Date.ComponentsFormatStyle](foundation/date/componentsformatstyle.md)
