---
title: "format(_:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/date/intervalformatstyle/format(_:)"
---

# format(_:)

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

## Declaration

```swift
func format(_ v: Range<Date>) -> String
```

## Parameters

- `v`: The date range to format.

## Return Value

Return Value A string representation of the date range.

## Discussion

Discussion The format(_:) instance method generates a string from the provided relative date. After you create a style, you can use it to format dates multiple times. The following example applies a format style multiple times to produce string representations of relative dates: if let pastWeek = Calendar.current.date(byAdding: .day, value: -7, to: Date()) {     if 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"     } }
