<!--
{
  "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/FormatStyle/relative(presentation:unitsStyle:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation11FormatStylePA2A4DateV08RelativebC0VRszrlE8relative12presentation05unitsC0A2G12PresentationV_AG05UnitsC0VtFZ"
  },
  "title" : "relative(presentation:unitsStyle:)"
}
-->

# relative(presentation:unitsStyle:)

Returns a style for formatting a date as relative to the current date.

```
static func relative(presentation: Date.RelativeFormatStyle.Presentation, unitsStyle: Date.RelativeFormatStyle.UnitsStyle = .wide) -> Self
```

## Parameters

`presentation`

The style to use when describing a relative date; for example, “1 day ago” or “yesterday”.

`unitsStyle`

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

## Return Value

A relative date format style customized with the specified presentation and unit styles.

## Discussion

Use this static method when the call point allows the use of [`Date.RelativeFormatStyle`](/documentation/Foundation/Date/RelativeFormatStyle). You typically do this when calling the [`formatted(_:)`](/documentation/Foundation/Date/formatted(_:)) method of [`Date`](/documentation/Foundation/Date).

The following example shows the [`relative(presentation:unitsStyle:)`](/documentation/Foundation/FormatStyle/relative(presentation:unitsStyle:)) relative format style with two different presentations.

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

---

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)