---
title: DateComponents
framework: foundation
role: symbol
role_heading: Structure
path: foundation/datecomponents
---

# DateComponents

A date or time specified in terms of units (such as year, month, day, hour, and minute) to be evaluated in a calendar system and time zone.

## Declaration

```swift
struct DateComponents
```

## Overview

Overview DateComponents encapsulates the components of a date in an extendable, structured manner. It is used to specify a date by providing the temporal components that make up a date and time in a particular calendar: hour, minutes, seconds, day, month, year, and so on. It can also be used to specify a duration of time, for example, 5 hours and 16 minutes. A DateComponents is not required to define all the component fields. When a new instance of DateComponents is created, the date components are set to nil.

## Topics

### Initializing Date Components

- [init(calendar:timeZone:era:year:month:day:hour:minute:second:nanosecond:weekday:weekdayOrdinal:quarter:weekOfMonth:weekOfYear:yearForWeekOfYear:)](foundation/datecomponents/init(calendar:timezone:era:year:month:day:hour:minute:second:nanosecond:weekday:weekdayordinal:quarter:weekofmonth:weekofyear:yearforweekofyear:).md)
- [calendar](foundation/datecomponents/calendar.md)
- [timeZone](foundation/datecomponents/timezone.md)

### Validating a Date

- [isValidDate](foundation/datecomponents/isvaliddate.md)
- [isValidDate(in:)](foundation/datecomponents/isvaliddate(in:).md)
- [date](foundation/datecomponents/date.md)

### Accessing Months and Years

- [era](foundation/datecomponents/era.md)
- [year](foundation/datecomponents/year.md)
- [yearForWeekOfYear](foundation/datecomponents/yearforweekofyear.md)
- [quarter](foundation/datecomponents/quarter.md)
- [month](foundation/datecomponents/month.md)
- [isLeapMonth](foundation/datecomponents/isleapmonth.md)

### Accessing Weeks and Days

- [weekOfMonth](foundation/datecomponents/weekofmonth.md)
- [weekOfYear](foundation/datecomponents/weekofyear.md)
- [weekday](foundation/datecomponents/weekday.md)
- [weekdayOrdinal](foundation/datecomponents/weekdayordinal.md)
- [day](foundation/datecomponents/day.md)

### Accessing Hours and Seconds

- [hour](foundation/datecomponents/hour.md)
- [minute](foundation/datecomponents/minute.md)
- [second](foundation/datecomponents/second.md)
- [nanosecond](foundation/datecomponents/nanosecond.md)

### Accessing Calendar Components

- [value(for:)](foundation/datecomponents/value(for:).md)
- [setValue(_:for:)](foundation/datecomponents/setvalue(_:for:).md)
- [Calendar.Component](foundation/calendar/component.md)

### Using Reference Types

- [NSDateComponents](foundation/nsdatecomponents.md)

### Structures

- [DateComponents.HTTPFormatStyle](foundation/datecomponents/httpformatstyle.md)
- [DateComponents.ISO8601FormatStyle](foundation/datecomponents/iso8601formatstyle.md)

### Initializers

- [init(_:strategy:)](foundation/datecomponents/init(_:strategy:)-62hv8.md)
- [init(_:strategy:)](foundation/datecomponents/init(_:strategy:)-84m93.md)
- [init(subscriptionPeriod:)](foundation/datecomponents/init(subscriptionperiod:).md)

### Instance Properties

- [dayOfYear](foundation/datecomponents/dayofyear.md)
- [isRepeatedDay](foundation/datecomponents/isrepeatedday.md)

### Instance Methods

- [formatted(_:)](foundation/datecomponents/formatted(_:).md)

### Type Aliases

- [DateComponents.Specification](foundation/datecomponents/specification.md)
- [DateComponents.UnwrappedType](foundation/datecomponents/unwrappedtype.md)
- [DateComponents.ValueType](foundation/datecomponents/valuetype.md)

### Type Properties

- [defaultResolverSpecification](foundation/datecomponents/defaultresolverspecification.md)

## Relationships

### Conforms To

- [Copyable](swift/copyable.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomReflectable](swift/customreflectable.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Decodable](swift/decodable.md)
- [Encodable](swift/encodable.md)
- [Equatable](swift/equatable.md)
- [Escapable](swift/escapable.md)
- [Hashable](swift/hashable.md)
- [IntentValueConvertible](appintents/intentvalueconvertible.md)
- [IntentValueExpressing](appintents/intentvalueexpressing.md)
- [ReferenceConvertible](foundation/referenceconvertible.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Calendrical Calculations

- [Calendar](foundation/calendar.md)
- [TimeZone](foundation/timezone.md)
