<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.9.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSCalendar/components(_:from:to:options:)-49lo8",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSCalendar(im)components:fromDateComponents:toDateComponents:options:"
  },
  "title" : "components(_:from:to:options:)"
}
-->

# components(_:from:to:options:)

Returns the difference between start and end dates given as date components.

```
func components(_ unitFlags: NSCalendar.Unit, from startingDateComp: DateComponents, to resultDateComp: DateComponents, options: NSCalendar.Options = []) -> DateComponents
```

## Parameters

`unitFlags`

Specifies the components for the returned `NSDateComponents` object.

`startingDateComp`

The start date for the calculation as an `NSDateComponents` object.

`resultDateComp`

The end date for the calculation as an `NSDateComponents` object.

`options`

The `options` parameter is currently unused.

## Return Value

An `NSDateComponents` object whose components are specified by `unitFlags` and calculated from the difference between the `startingDateComp` and `resultDateComp` using the options specified by `options`. Returns `nil` if either date falls outside the defined range of the receiver or if the computation cannot be performed.

## Discussion

If an `NSDateComponents` object does not specify a value for a calendar unit required to determine an absolute date, the base value of that unit is assumed. For example, given an `NSDateComponents` object with only a `year` and a `month` specified, the resulting `NSDate` object would be constructed using a `day` value of `1` and `hour`, `minute`, `second` and `nanosecond` values of `0`. Passing an `NSDateComponents` argument with an unspecified `era` or `year` value is not advised.

If an `NSDateComponents` object’s `timeZone` property is set, the time zone property value will be used in the calculation. If an `NSDateComponents` object’s `calendar` property is set, the calendar property value will be used instead of the receiving calendar. If both an `NSDateComponents` object’s `timeZone` and `calendar` properties are set, the time zone property value overrides the time zone of the calendar property value.

---

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)