DateWithinQ[date1,date2]
returns True if the calendar date date2 is entirely contained within date1, and False otherwise.
DateWithinQ
DateWithinQ[date1,date2]
returns True if the calendar date date2 is entirely contained within date1, and False otherwise.
Details
- In DateWithinQ[date1, date2], both date1 and date2 should be specified as DateObject expressions of any calendar granularity.
- DateWithinQ accepts lists of dates in both arguments, effectively calling Outer on the input lists.
- DateWithinQ returns True only if date2 falls entirely within the period represented by date1.
Examples
open all close allBasic Examples (2)
DateWithinQ[Today, Now]But it does not fall within Yesterday:
DateWithinQ[Yesterday, Now]Test whether a given date is within the year 2022:
DateWithinQ[DateObject[{2022}, "Year"], DateObject[{2022, 8, 4}, "Day"]]Scope (3)
Test whether a date is within several dates:
DateWithinQ[{Yesterday, Today, Tomorrow}, Now]Test whether several dates are within a given date:
DateWithinQ[DateObject[{2022}, "Year"], {DateObject[{2022, 5, 9}, "Day"], DateObject[{2021, 8, 4}, "Day"], DateObject[{2022, 4}, "Month"]}]Test for containment of several dates within several other dates:
DateWithinQ[{DateObject[{2022}, "Year"], DateObject[{2021, 12}, "Month"]}, {DateObject[{2022, 6, 17}, "Day"], DateObject[{2021, 12, 25}, "Day"], Entity["Country", "SouthKorea"][EntityProperty["Country", "IndependenceDate"]]}]Properties & Relations (3)
DateWithinQ will return True only if date2 is entirely contained within date1:
DateWithinQ[DateObject[{2022, 1}, "Month"], DateObject[{2022, 1, 31}, "Week"]]DateOverlapsQ can be used to test for partial containment:
DateOverlapsQ[DateObject[{2022, 1}, "Month"], DateObject[{2022, 1, 31}, "Week"]]If a date object is within another, their difference will be zero of the largest calendar granularity:
DateWithinQ[DateObject[{2022}, "Year"], DateObject[{2022, 5, 9}, "Day"]]DateObject[{2022, 5, 9}, "Day"] - DateObject[{2022}, "Year"]If a date object is within another, they cannot be compared because they overlap:
DateWithinQ[DateObject[{2023, 8}, "Month"], DateObject[{2023, 8, 4}, "Day"]]DateObject[{2023, 8}, "Month"] < DateObject[{2023, 8, 4}, "Day"]Related Guides
History
Text
Wolfram Research (2017), DateWithinQ, Wolfram Language function, https://reference.wolfram.com/language/ref/DateWithinQ.html.
CMS
Wolfram Language. 2017. "DateWithinQ." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/DateWithinQ.html.
APA
Wolfram Language. (2017). DateWithinQ. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/DateWithinQ.html
BibTeX
@misc{reference.wolfram_2026_datewithinq, author="Wolfram Research", title="{DateWithinQ}", year="2017", howpublished="\url{https://reference.wolfram.com/language/ref/DateWithinQ.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_datewithinq, organization={Wolfram Research}, title={DateWithinQ}, year={2017}, url={https://reference.wolfram.com/language/ref/DateWithinQ.html}, note=[Accessed: 12-June-2026]}