DateInterval

DateInterval[{start,end}]

represents the continuous interval of time between start and end.

DateInterval[{start,end},gran]

represents an interval of dates with calendar granularity gran.

DateInterval[{{start1,end1},{start2,end2},}]

represents the union of intervals start1 to end1, start2 to end2, .

DateInterval[gdate]

gives the date interval from the initial to final instants of the granular date object gdate.

Details and Options

  • DateInterval[{start,end}] represents the continuous interval of time that begins with the date start and ends with the date end.
  • Input dates in DateInterval can be specified as DateObject expressions, date lists, absolute times or date strings.
  • DateInterval[,gran] represents the collection of granular date objects of calendar granularity gran contained within the specified period. Possible calendar granularity specifications include:
  • "Millennium"1000-year period beginning with year XX00
    "MillenniumBeginning01"1000-year period beginning with year XX01
    "Century"100-year period beginning with year XX00
    "CenturyBeginning01"100-year period beginning with year XX01
    "Decade"10-year period including the date
    "Year"year including the date
    "Quarter"3-month quarter including the date
    "Month"month including the date
    "Week"week beginning Monday including the date
    "WeekBeginningSunday"week beginning Sunday including the date
    "Day"day including the date
    "Hour"hour including the date
    "Minute"minute including the date
    "Second"second including the date
    "Instant"the exact instant specified
  • DateInterval[{start,end},gran] normalizes its input dates to the specified granularity. DateInterval[{start,end}] uses the finest granularity of the start and end dates.
  • For {start,end} pairs, DateInterval includes the first instant associated with the start date and excludes the final instant associated with the end date.
  • When the granularity for the start and end dates is changed, the date interval will automatically expand to include the largest possible period compatible with their granularity.
  • DateInterval supports arithmetic and date-related computations.
  • Min[interval] and Max[interval] give the endpoints of a date interval.
  • The following options can be given:
  • CalendarTypeAutomaticcalendar system being used
    DateGranularityAutomaticcalendar granularity for the date
    TimeZoneAutomatictime zone being used
  • DateInterval[][prop] gives the specified property of a date interval.
  • Possible properties include:
  • "CalendarType"calendar associated with the interval
    "DateBounds"first and last dates for the interval
    "Dates"DateObject representation of boundary dates
    "Duration"length of the interval as a Quantity object
    "Granularity"calendar granularity associated with the interval
    "Min"earliest date of the interval
    "Max"final date of the interval
    "TimeZone"time zone associated with the interval

Examples

open allclose all

Basic Examples  (3)

Represent the period of time from one date to another:

Draw it on a timeline:

Get the date interval corresponding to today:

Find the current temporal distance to the beginning and end of today:

Represent the collection of days within the current month:

Scope  (6)

Interval Operations  (3)

DateInterval expressions may be used in interval operations such as IntervalMemberQ:

DateOverlapsQ may be used to test partial overlap for intervals that are not fully contained:

IntervalUnion may be used to combine multiple date intervals into a single expression:

IntervalIntersection will give the interval of time common to each interval:

Arithmetic  (2)

Add a duration to a date interval:

Find the difference of a date interval and a given date:

Visualization  (1)

Visualize a date interval using TimelinePlot:

Properties & Relations  (1)

Use Min and Max to find endpoints of date intervals:

DateBounds may also be used to find the endpoints:

Possible Issues  (1)

DateInterval accepts AbsoluteTime specifications for single-interval inputs:

In the case of a multi-interval, a list of pairs will be treated as a DateList specification:

FromAbsoluteTime may be used to disambiguate cases with absolute time specifications:

Wolfram Research (2020), DateInterval, Wolfram Language function, https://reference.wolfram.com/language/ref/DateInterval.html (updated 2023).

Text

Wolfram Research (2020), DateInterval, Wolfram Language function, https://reference.wolfram.com/language/ref/DateInterval.html (updated 2023).

CMS

Wolfram Language. 2020. "DateInterval." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2023. https://reference.wolfram.com/language/ref/DateInterval.html.

APA

Wolfram Language. (2020). DateInterval. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/DateInterval.html

BibTeX

@misc{reference.wolfram_2024_dateinterval, author="Wolfram Research", title="{DateInterval}", year="2023", howpublished="\url{https://reference.wolfram.com/language/ref/DateInterval.html}", note=[Accessed: 14-October-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_dateinterval, organization={Wolfram Research}, title={DateInterval}, year={2023}, url={https://reference.wolfram.com/language/ref/DateInterval.html}, note=[Accessed: 14-October-2024 ]}