---
title: "component(_:from:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nscalendar/component(_:from:)"
---

# component(_:from:)

Returns the specified date component from a given date.

## Declaration

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

## Parameters

- `unit`: The component to return. For possible values, see doc://com.apple.foundation/documentation/Foundation/NSCalendar/Unit.
- `date`: The date for which to perform the calculation.

## Return Value

Return Value An NSInteger value for the requested component.

## See Also

### Extracting Components

- [date(_:matchesComponents:)](foundation/nscalendar/date(_:matchescomponents:).md)
- [components(_:from:)](foundation/nscalendar/components(_:from:).md)
- [components(_:from:to:options:)](foundation/nscalendar/components(_:from:to:options:)-84y5w.md)
- [components(_:from:to:options:)](foundation/nscalendar/components(_:from:to:options:)-49lo8.md)
- [components(in:from:)](foundation/nscalendar/components(in:from:).md)
- [getEra(_:year:month:day:from:)](foundation/nscalendar/getera(_:year:month:day:from:).md)
- [getEra(_:yearForWeekOfYear:weekOfYear:weekday:from:)](foundation/nscalendar/getera(_:yearforweekofyear:weekofyear:weekday:from:).md)
- [getHour(_:minute:second:nanosecond:from:)](foundation/nscalendar/gethour(_:minute:second:nanosecond:from:).md)
