---
title: "string(from:to:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/datecomponentsformatter/string(from:to:)"
---

# string(from:to:)

Returns a formatted string based on the time difference between two dates.

## Declaration

```swift
func string(from startDate: Date, to endDate: Date) -> String?
```

## Parameters

- `startDate`: The start time. This parameter must not be nil.
- `endDate`: The end time. This parameter must not be nil.

## Return Value

Return Value A formatted string representing the specified time information.

## Discussion

Discussion This method calculates the elapsed time between the startDate and endDate values and uses that information to generate the string. For example, if there is exactly one hour and ten minutes difference between the start and end dates, generating an abbreviated string would result in a string of “1h 10m”.

## See Also

### Formatting Values

- [string(from:)](foundation/datecomponentsformatter/string(from:)-9exxn.md)
- [string(for:)](foundation/datecomponentsformatter/string(for:).md)
- [string(from:)](foundation/datecomponentsformatter/string(from:)-7sj4j.md)
- [localizedString(from:unitsStyle:)](foundation/datecomponentsformatter/localizedstring(from:unitsstyle:).md)
