<!--
{
  "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/component(_:from:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSCalendar(im)component:fromDate:"
  },
  "title" : "component(_:from:)"
}
-->

# component(_:from:)

Returns the specified date component from a given date.

```
func component(_ unit: NSCalendar.Unit, from date: Date) -> Int
```

## Parameters

`unit`

The component to return. For possible values, see [`NSCalendar.Unit`](/documentation/Foundation/NSCalendar/Unit).

`date`

The date for which to perform the calculation.

## Return Value

An `NSInteger` value for the requested component.

## Discussion

---

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)