DateSelect[list,crit]
picks out all dates datei of a list for which crit[datei] is True.
DateSelect[int,crit]
returns all dates within the DateInterval int for which crit[datei] is True.
DateSelect[crit]
represents an operator form of DateSelect that can be applied to an expression.
DateSelect
DateSelect[list,crit]
picks out all dates datei of a list for which crit[datei] is True.
DateSelect[int,crit]
returns all dates within the DateInterval int for which crit[datei] is True.
DateSelect[crit]
represents an operator form of DateSelect that can be applied to an expression.
Details
- DateSelect is typically used to filter out dates that satisfy a criterion, such as falling in a specific month or day of the week.
- In DateSelect[list,crit], crit is a Boolean expression, typically composed of date element tests, such as #Month==8 or #DayName==Monday.
- DateSelect supports all date elements available in DateValue, including "Year", "Month", "DayName" and "Week", expressed as a named Slot such as #Year, #Month, etc.
- For DateInterval inputs, DateSelect returns a list of dates using the calendar granularity specified by the interval.
Examples
open all close allBasic Examples (4)
Select all dates in May within a given list of dates:
DateSelect[{DateObject[{2022, 5, 1}, "Day"], DateObject[{2023, 5, 30}, "Day"], DateObject[{2024, 6, 23}, "Day"]}, #Month == 5&]Get all dates within the 8th week of the year:
DateSelect[DateRange[DateObject[{2022, 1, 1}, "Day"], DateObject[{2022, 12, 31}, "Day"]], #Week == 8&]Get all Wednesdays within a given date interval:
DateSelect[DateInterval[{{{2020, 4, 1}, {2020, 4, 30}}}, "Day", "Gregorian", -5.], #DayName == Wednesday&]Select any instance of February 4, as well as all Thursdays within the given range:
DateSelect[DateRange[DateObject[{2022, 1, 1}, "Day"], DateObject[{2022, 3, 31}, "Day"]], ((#Month == 2 && #Day == 4) || #DayName == Thursday)&]Make a selection function to find the fourth day of each odd-numbered month:
fun = DateSelect[(OddQ[#Month] && #Day == 4)&];Apply the function to a specific date range:
fun[DateRange[DateObject[{2022, 1, 1}, "Day"], DateObject[{2022, 3, 31}, "Day"]]]Scope (2)
Selection criteria are typically reference date elements using Slot expressions but may use any Boolean criteria:
DateSelect[DateRange[DateObject[{2022, 1, 1}, "Day"], DateObject[{2022, 3, 31}, "Day"]], StringContainsQ[DateString[#], "Tue 1"]&]DateSelect extracts element values without converting calendars or changing time zones:
dates = CalendarConvert[{DateObject[{2020, 9, 21}, "Day", "Gregorian", -5.], DateObject[{2020, 9, 22}, "Day", "Gregorian", -5.], DateObject[{2020, 9, 23}, "Day", "Gregorian", -5.]}, "Jewish"]The value of #Day is determined by the calendar associated with the input date:
DateSelect[dates, #Day > 20&]DateSelect[dates, #Day < 6&]The value of #Hour is checked without accounting for differences in time zones:
DateSelect[{DateObject[{2020, 9, 23, 0, 54, 53.816753}, "Instant", "Gregorian", 5.], DateObject[{2020, 9, 22, 19, 54, 53.816941}, "Instant", "Gregorian", 0.], DateObject[{2020, 9, 22, 14, 54, 53.817006}, "Instant", "Gregorian", -5.]}, #Hour == 14&]To select dates using a standardized time zone, first use TimeZoneConvert:
DateSelect[TimeZoneConvert[{DateObject[{2020, 9, 23, 0, 54, 53.816753}, "Instant", "Gregorian", 5.], DateObject[{2020, 9, 22, 19, 54, 53.816941}, "Instant", "Gregorian", 0.], DateObject[{2020, 9, 22, 14, 54, 53.817006}, "Instant", "Gregorian", -5.]}, -5], #Hour == 14&]Applications (1)
DateSelect can be used for scheduling purposes, picking out dates that match a given pattern, such as the first Monday in any given month:
criteria = #DayName == Monday && #DayNameInstanceInMonth == 1&;DateSelect[DateInterval[{DateObject[{2020, 1, 1}], DateObject[{2020, 12, 31}]}], criteria]Properties & Relations (1)
DateSelect[dates,crit] is equivalent to Select[dates,DateValue[#,elem]==value&]
dates = {DateObject[{2020, 9, 20}, "Day", "Gregorian", -5.], DateObject[{2020, 9, 21}, "Day", "Gregorian", -5.], DateObject[{2020, 9, 22}, "Day", "Gregorian", -5.]};DateSelect[dates, #DayName == Monday&]Select[dates, DateValue[#, "DayName"] == Monday&]Possible Issues (1)
Not all calendars include all elements as selection criteria:
DateSelect[{DateObject[{1442, 2, 4}, "Day", "Islamic", -5.]}, #Quarter < 5&]DateValue[DateObject[{1442, 2, 4}, "Day", "Islamic", -5.], "Quarter"]Dates may be converted to a different calendar prior to selection using CalendarConvert:
DateSelect[CalendarConvert[{DateObject[{1442, 2, 4}, "Day", "Islamic", -5.]}, "Gregorian"], #Quarter < 5&]Neat Examples (3)
On the Gregorian calendar, the 13th day of the month is a Friday more frequently than any other day of the week:
SortBy[Tally[DateValue[DateSelect[DateInterval[{{2001, 1, 1}, {2400}}, "Day"], #Day == 13&], "DayName"]], Last]Create a criterion for US presidential elections (first Tuesday after the first Monday in November every 4 years):
election = Divisible[#Year, 4] && #Month == 11 && #DayName == Tuesday && Or[#DayNameInstanceInMonth == 1 && #Day =!= 1, #DayNameInstanceInMonth == 2 && #Day == 8]&;Use the criterion to find all presidential election days in a 20-year period:
DateSelect[DateInterval[{{2020}, {2040}}, "Day"], election]A Gregorian century never begins on a Sunday, regardless of whether it starts on year 1 or year zero:
DateSelect[DateInterval[{{2000}, {2400}}, "Day"], Divisible[#Year, 100] && #Month == 1 && #Day == 1 && #DayName == Sunday&]DateSelect[DateInterval[{{2001}, {2401}}, "Day"], Divisible[#Year - 1, 100] && #Month == 1 && #Day == 1 && #DayName == Sunday&]Related Guides
History
Text
Wolfram Research (2020), DateSelect, Wolfram Language function, https://reference.wolfram.com/language/ref/DateSelect.html.
CMS
Wolfram Language. 2020. "DateSelect." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/DateSelect.html.
APA
Wolfram Language. (2020). DateSelect. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/DateSelect.html
BibTeX
@misc{reference.wolfram_2026_dateselect, author="Wolfram Research", title="{DateSelect}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/DateSelect.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_dateselect, organization={Wolfram Research}, title={DateSelect}, year={2020}, url={https://reference.wolfram.com/language/ref/DateSelect.html}, note=[Accessed: 13-June-2026]}