---
title: "relative(presentation:unitsStyle:)"
framework: foundation
role: symbol
role_heading: Type Method
path: "foundation/formatstyle/relative(presentation:unitsstyle:)"
---

# relative(presentation:unitsStyle:)

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

## Declaration

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

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

## Discussion

Discussion Use this static method when the call point allows the use of Date.RelativeFormatStyle. You typically do this when calling the formatted(_:) method of Date. The following example shows the relative(presentation:unitsStyle:) relative format style with two different presentations. 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" }

## 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)
- [Date.RelativeFormatStyle](foundation/date/relativeformatstyle.md)
- [components(style:fields:)](foundation/formatstyle/components(style:fields:).md)
- [Date.ComponentsFormatStyle](foundation/date/componentsformatstyle.md)
