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 and an endDate. The startDate and endDate of a date interval can be equal, in which case its duration is 0. However, endDate cannot occur earlier than startDate.

You can use the DateIntervalFormatter class to create string representations of NSDateInterval objects that are suitable for display in the current locale.


Accessing Start Date, End Date, and Duration

var startDate: Date

The start date of the date interval.

var endDate: Date

The end date of the date interval.

var duration: TimeInterval

The duration of the date interval.

Creating Date Intervals


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

init(start: Date, duration: TimeInterval)

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

init(start: Date, end: Date)

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

Comparing Date Intervals

func compare(DateInterval)

Returns the result of comparing the receiver with the specified date interval.

func isEqual(to: DateInterval)

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

Determining Intersections

func intersects(DateInterval)

Returns whether the receiver intersects with the specified date interval.

func intersection(with: DateInterval)

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

Determining Whether a Date Occurs Within a Date Interval

func contains(Date)

Returns whether the receiver contains the specified date.


Inherits From