---
title: "dateComponents(_:from:to:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/calendar/datecomponents(_:from:to:)-2kcg"
---

# dateComponents(_:from:to:)

Returns the difference between two dates.

## Declaration

```swift
func dateComponents(_ components: Set<Calendar.Component>, from start: Date, to end: Date) -> DateComponents
```

## Parameters

- `components`: Which components to compare.
- `start`: The starting date.
- `end`: The ending date.

## Return Value

Return Value The result of calculating the difference from start to end.

## See Also

### Extracting Components

- [date(_:matchesComponents:)](foundation/calendar/date(_:matchescomponents:).md)
- [component(_:from:)](foundation/calendar/component(_:from:).md)
- [dateComponents(_:from:)](foundation/calendar/datecomponents(_:from:).md)
- [dateComponents(_:from:to:)](foundation/calendar/datecomponents(_:from:to:)-5g20t.md)
- [dateComponents(in:from:)](foundation/calendar/datecomponents(in:from:).md)
- [Calendar.Component](foundation/calendar/component.md)
