DayRange
更多信息和选项
- DayRange 返回一个 DateObject 元素的列表.
- 日期可以使用下列格式指定:
-
DateObject[…] 日期对象 {y,m,d} 年,月,日 {y,m} 指定月份的第一天 {y} y 年的 1 月1 日 "string" 作为字符串给出的日期("Jan. 1, 2000") {y,m,d,h,m,s} 精确的时间 time 绝对时间 - 可用的日期类型有:
-
All 任何日历中的日期(默认) "Weekday" 被视为工作日的日期 "Weekend" 被视为周末的日期 "Holiday" 由 HolidayCalendar 规定的假期 "NonHoliday" 不是假期的日期 "BusinessDay" 非假期工作日 "NonBusinessDay" 假期或周末 "WeekdayHoliday" 发生在工作日的假期 "WeekendHoliday" 发生在周末的假期 "WeekendNonHoliday" 非假期的周末 Monday, Tuesday, … 一周的某一天 "EndOfMonth" 给定月份的最后一天 "BeginningOfMonth" 给定月份的第一天 - 在犹太历中,工作日是 Sunday 到 Thursday.
- DayRange 使用下列选项:
-
CalendarType Automatic 指定日期所使用的日历 HolidayCalendar {"UnitedStates","Default"} 假期安排和子指定,用于工作日和假期计算 "IncludeEndPoints" {True,True} date1 和 date2 是否包含在范围内
范例
打开所有单元 关闭所有单元基本范例 (4)
DayRange[Yesterday, Tomorrow]With[{first = Take[DateList[], 2]}, DayRange[first, DatePlus[first, {{1, "Month"}, {-1, "Day"}}], Sunday]]DayRange[DateObject[{2022, 1, 1}], DateObject[{2022, 1, 31}], "BusinessDay"]With[{firstday = DayRound[CurrentDate["Year"]]}, DayRange[firstday, DatePlus[firstday, {{1, "Year"}, {-1, "Day"}}], "Holiday"]]范围 (1)
选项 (4)
CalendarType (1)
HolidayCalendar (2)
DayRange[{2012}, {2012, 12, 31}, "Holiday", HolidayCalendar -> "India"]CalendarData["UnitedStates"]With[{first = {2012, 4}}, DayRange[first, DatePlus[first, {{1, "Month"}}], "Holiday", HolidayCalendar -> {"UnitedStates", "NYSE"}]]With[{first = {2012, 4}}, DayRange[first, DatePlus[first, {{1, "Month"}}], "Holiday"]]应用 (1)
计算直至下次美国总统大选的天数(闰年11月里的第一个星期一后的第一个星期二):
nextelection[date_] := Module[{year = 4Ceiling[date[[1]] / 4], nearest},
nearest = DatePlus[DayRange[{year, 11, 1}, {year, 11, 30}, Monday][[1]], 1];
If[QuantityMagnitude[DateDifference[date, nearest]] > 0, DayCount[date, nearest], DayCount[date, DatePlus[DayRange[{year + 4, 11, 1}, {year + 4, 11, 30}, Monday][[1]], 1]]]//Floor];
nextelection[DateList[]]属性和关系 (3)
对于同样的输入集合,DayCount 等价于由 DayRange 输出的列表的长度:
With[{first = Take[DateList[], 2]}, Length[DayRange[first, DatePlus[first, {{1, "Month"}, {-1, "Day"}}], "BusinessDay", "IncludeEndPoints" -> {False, True}]] == DayCount[first, DatePlus[first, {{1, "Month"}, {-1, "Day"}}], "BusinessDay"]]具有 All 以外的日期类型指定的 DayRange 等价于 Select 语句:
DayRange[{2022}, {2023}, "Weekend"] == Select[DayRange[{2022}, {2023}], DayMatchQ[#, "Weekend"]&]With[{sets = {DayRange[{2022}, {2023}, "Holiday"], DayRange[{2022}, {2023}, "Weekend"], DayRange[{2022}, {2023}, "BusinessDay"]}}, Union@@sets == ((Join@@sets)//Sort)]可能存在的问题 (1)
With[{first = {2012, 7}}, DayRange[first, DatePlus[first, {{1, "Month"}, {-1, "Day"}}], "Weekend"]]With[{first = {2012, 7}}, DayRange[first, DatePlus[first, {{1, "Month"}, {-1, "Day"}}], "Holiday", HolidayCalendar -> {"Gregorian" -> {{True&, # == 7&, 1 ≤ # ≤ 31&}}}]]相关指南
-
▪
- 日期和时间
文本
Wolfram Research (2012),DayRange,Wolfram 语言函数,https://reference.wolfram.com/language/ref/DayRange.html (更新于 2025 年).
CMS
Wolfram 语言. 2012. "DayRange." Wolfram 语言与系统参考资料中心. Wolfram Research. 最新版本 2025. https://reference.wolfram.com/language/ref/DayRange.html.
APA
Wolfram 语言. (2012). DayRange. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/DayRange.html 年
BibTeX
@misc{reference.wolfram_2026_dayrange, author="Wolfram Research", title="{DayRange}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/DayRange.html}", note=[Accessed: 16-September-2026]}
BibLaTeX
@online{reference.wolfram_2026_dayrange, organization={Wolfram Research}, title={DayRange}, year={2025}, url={https://reference.wolfram.com/language/ref/DayRange.html}, note=[Accessed: 16-September-2026]}