<!--
{
  "availability" : [
    "iOS: 10.0.0 -",
    "iPadOS: 10.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.12.0 -",
    "tvOS: 10.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 3.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSDateInterval",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSDateInterval"
  },
  "title" : "NSDateInterval"
}
-->

# NSDateInterval

An object representing the span of time between a specific start date and end date.

```
class NSDateInterval
```

## Overview

In Swift, this object bridges to [`DateInterval`](/documentation/Foundation/DateInterval); use [`NSDateInterval`](/documentation/Foundation/NSDateInterval) when you need reference semantics or other Foundation-specific behavior.

An `NSDateInterval` object represents a closed interval between two dates. The `NSDateInterval` class provides a programmatic interface for calculating the duration of a time interval and determining whether a date falls within it, as well as comparing date intervals and checking to see whether they intersect.

An `NSDateInterval` object consists of a [`startDate`](/documentation/Foundation/NSDateInterval/startDate) and an [`endDate`](/documentation/Foundation/NSDateInterval/endDate). The [`startDate`](/documentation/Foundation/NSDateInterval/startDate) and [`endDate`](/documentation/Foundation/NSDateInterval/endDate) of a date interval can be equal, in which case its [`duration`](/documentation/Foundation/NSDateInterval/duration) is `0`. However, [`endDate`](/documentation/Foundation/NSDateInterval/endDate) cannot occur earlier than [`startDate`](/documentation/Foundation/NSDateInterval/startDate).

You can use the [`DateIntervalFormatter`](/documentation/Foundation/DateIntervalFormatter) class to create string representations of `NSDateInterval` objects that are suitable for display in the current locale.

> Important:
> The Swift overlay to the Foundation framework provides the ``doc://com.apple.foundation/documentation/Foundation/DateInterval`` structure, which bridges to the `NSDateInterval` class. For more information about value types, see <doc://com.apple.documentation/documentation/Swift/working-with-foundation-types>.

## Topics

### Creating Date Intervals

[`-  init`](/documentation/Foundation/NSDateInterval/init())

Initializes a date interval by setting the start and end date to the current date.

[`-  initWithStartDate:duration:`](/documentation/Foundation/NSDateInterval/init(start:duration:))

Initializes a date interval with a given start date and duration.

[`-  initWithStartDate:endDate:`](/documentation/Foundation/NSDateInterval/init(start:end:))

Initializes a date interval from a given start date and end date.

[`-  initWithCoder:`](/documentation/Foundation/NSDateInterval/init(coder:))

Returns a date interval initialized from data in the given unarchiver.

### Accessing Start Date, End Date, and Duration

[`startDate`](/documentation/Foundation/NSDateInterval/startDate)

The start date of the date interval.

[`endDate`](/documentation/Foundation/NSDateInterval/endDate)

The end date of the date interval.

[`duration`](/documentation/Foundation/NSDateInterval/duration)

The duration of the date interval.

### Comparing Date Intervals

[`-  compare:`](/documentation/Foundation/NSDateInterval/compare(_:))

Compares the receiver with the specified date interval.

[`-  isEqualToDateInterval:`](/documentation/Foundation/NSDateInterval/isEqual(to:))

Indicates whether the receiver is equal to the specified date interval.

### Determining Intersections

[`-  intersectsDateInterval:`](/documentation/Foundation/NSDateInterval/intersects(_:))

Indicates whether the receiver intersects with the specified date interval.

[`-  intersectionWithDateInterval:`](/documentation/Foundation/NSDateInterval/intersection(with:))

Returns the intersection between the receiver and the specified date interval.

### Determining Whether a Date Occurs Within a Date Interval

[`-  containsDate:`](/documentation/Foundation/NSDateInterval/contains(_:))

Indicates whether the receiver contains the specified date.

## Relationships

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

### Conforms To

[`Hashable`](/documentation/Swift/Hashable)

[`CVarArg`](/documentation/Swift/CVarArg)

[`Equatable`](/documentation/Swift/Equatable)

[`Escapable`](/documentation/Swift/Escapable)

[`NSCopying`](/documentation/Foundation/NSCopying)

[`NSCoding`](/documentation/Foundation/NSCoding)

[`Copyable`](/documentation/Swift/Copyable)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`Sendable`](/documentation/Swift/Sendable)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`NSSecureCoding`](/documentation/Foundation/NSSecureCoding)

---

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)