Skip to content

time.calendars

calendar questions: weekdays, business days, holidays, week numbers, month grids, cron schedules, zodiac signs

Answers questions about the calendar rather than the clock: which weekday a date is, which week or quarter, how many business days apart, which days are holidays, a month grid, and when a cron schedule fires.

Tags: time

  • weekday_num the day of the week as a number, from 1 for Monday to 7 for Sunday
  • day_of_year which day of the year it is, from 1 to 366
  • iso_week the week number by the ISO standard used in Europe and business
  • week_num the week number when weeks start on first_day, where week 1 is the week with January 1
  • year_frac the length of time from a to b as a number of years, by a day-count basis
  • quarter which quarter of the year the date is in, 1 to 4
  • leap_year whether the year is a leap year
  • days_in_month how many days the date’s month has
  • days_in_year how many days the date’s year has, 365 or 366
  • start_of the first moment of the period the date is in
  • end_of the last moment of the period the date is in, with periods as for start_of
  • next the first date after d that falls on the given weekday, never d itself
  • prev the latest date before d that falls on the given weekday, never d itself
  • nth_weekday the nth given weekday in d’s month, like the 4th Thursday
  • add_workdays the date n business days later, counting only Monday to Friday and skipping holidays
  • workdays how many business days (Monday to Friday, less holidays) there are from a up to, but not including, b
  • holidays a year’s public holidays, on the day they’re taken off when they fall on a weekend
  • cron a cron schedule in plain English
  • calendar a month drawn as a calendar grid, weeks starting on Monday
  • zodiac the Western star sign for a birthday (today without one)
  • chinese_zodiac the Chinese zodiac element and animal for a year
weekday_num(d: date) -> int

the day of the week as a number, from 1 for Monday to 7 for Sunday

1
today.weekday_num3
Example outputCtrl+Enter to run

See also weekday

day_of_year(d: date) -> int

which day of the year it is, from 1 to 366

1
date("2026-12-31").day_of_year365
Example outputCtrl+Enter to run

See also iso_week

iso_week(d: date) -> int

the week number by the ISO standard used in Europe and business

Weeks start on Monday, and week 1 is the one with the year’s first Thursday

1
date("2026-12-31").iso_week53
Example outputCtrl+Enter to run

See also day_of_year, week_num, quarter

week_num(d: date, first_day?: str) -> int

the week number when weeks start on first_day, where week 1 is the week with January 1

With no first_day this is iso_week. first_day is a day’s name, like “monday” or “sun”, and “sunday” gives the US numbering

1
date("2026-12-31").week_num("sunday")53
Example outputCtrl+Enter to run

See also iso_week, day_of_year

year_frac(a: date, b: date, basis?: str) -> float

the length of time from a to b as a number of years, by a day-count basis

basis is “actual/actual” (the default), “30/360”, “30E/360”, “actual/360” or “actual/365”, the conventions bonds and loans use

1
year_frac(date("2026-01-15"), date("2026-07-15"), "30/360")0.5
Example outputCtrl+Enter to run

See also days_in_year

quarter(d: date) -> int

which quarter of the year the date is in, 1 to 4

1
today.quarter4
Example outputCtrl+Enter to run

See also iso_week

leap_year(d: date|int) -> bool

whether the year is a leap year

1
leap_year(2028)true
2
today.leap_yearfalse
Example outputCtrl+Enter to run

See also days_in_year

days_in_month(d: date) -> int

how many days the date’s month has

1
date("2028-02-10").days_in_month29
Example outputCtrl+Enter to run

See also days_in_year

days_in_year(d: date) -> int

how many days the date’s year has, 365 or 366

1
today.days_in_year365
Example outputCtrl+Enter to run

See also leap_year, year_frac

start_of(d: date, period: str) -> date

the first moment of the period the date is in

period is “second”, “minute”, “hour”, “day”, “week” (starting Monday), “month”, “quarter” or “year”

1
now.start_of("week")2026-11-02
2
now.start_of("quarter")2026-10-01
Example outputCtrl+Enter to run

See also end_of, with

end_of(d: date, period: str) -> date

the last moment of the period the date is in, with periods as for start_of

1
now.end_of("month")2026-11-30 23:59:59 -06:00
2
(today.end_of("year") - now).parts"57 d 11 h 47 min"
Example outputCtrl+Enter to run

See also start_of

next(d: date, weekday: str) -> date / next(cron: str, n?: int) -> date|list

the first date after d that falls on the given weekday, never d itself

weekday is a day’s name, like “friday”, or its first 3 or more letters, like “fri”. Given a cron expression instead, when it next runs, or a list of the next n times

1
today.next("friday")2026-11-06
2
now.next("mon")2026-11-09 12:12:40 -06:00
3
"0 9 * * mon".next2026-11-09 09:00:00 -06:00
4
"@monthly".next(2)[2026-12-01, 2027-01-01]
Example outputCtrl+Enter to run

See also prev, nth_weekday, cron

prev(d: date, weekday: str) -> date

the latest date before d that falls on the given weekday, never d itself

weekday is a day’s name, like “sunday”, or its first 3 or more letters, like “sun”

1
today.prev("sunday")2026-11-01
Example outputCtrl+Enter to run

See also next

nth_weekday(d: date, n: int, weekday: str) -> date

the nth given weekday in d’s month, like the 4th Thursday

-1 is the last one, -2 the one before. weekday is a day’s name, like “thursday”, or its first 3 or more letters, like “thu”

1
date(2026, 11, 1).nth_weekday(4, "thu")2026-11-26
2
date(2026, 5, 1).nth_weekday(-1, "mon")2026-05-25
Example outputCtrl+Enter to run

See also next

add_workdays(d: date, n: int, holidays?: list|str) -> date

the date n business days later, counting only Monday to Friday and skipping holidays

holidays is a list of dates, or “US” or “UK” for those public holidays. A negative n goes back

1
today.add_workdays(10)2026-11-18
2
date("2026-12-24").add_workdays(1, "US")2026-12-28
3
date("2026-12-24").add_workdays(1, [date("2026-12-28")])2026-12-25
Example outputCtrl+Enter to run

See also workdays, holidays, is_weekend

workdays(a: date, b: date, holidays?: list|str) -> int

how many business days (Monday to Friday, less holidays) there are from a up to, but not including, b

1
workdays(today, date("2026-12-25"))37
2
workdays(date("2026-12-01"), date("2027-01-01"), "UK")21
Example outputCtrl+Enter to run

See also add_workdays, holidays

holidays(year: int, country: str) -> list

a year’s public holidays, on the day they’re taken off when they fall on a weekend

“US” gives federal holidays and “UK” bank holidays in England

1
holidays(2026, "US")[2026-01-01, 2026-01-19, 2026-02-16, 2026-05-25, 2026-06-19, 2026-07-03, 2026-09-07, 2026-10-12, 2026-11-11, 2026-11-26, 2026-12-25]
2
holidays(2026, "UK").len8
Example outputCtrl+Enter to run

See also add_workdays, workdays

cron(expr: str) -> str

a cron schedule in plain English

Cron, the Unix job scheduler, writes schedules as five fields, minute hour day-of-month month weekday, where * means every and */15 every 15th, or a shortcut like @daily

1
cron("0 9 * * 1-5")"at 09:00, on Monday through Friday"
2
cron("30 4 1,15 * fri")"at 04:30, on days 1 and 15 of the month, or on Friday"
3
cron("@hourly")"at minute 0 of every hour"
Example outputCtrl+Enter to run

See also next

calendar(d: date) -> str / calendar(year: int, month: int) -> str

a month drawn as a calendar grid, weeks starting on Monday

1
calendar(2026, 12)
December 2026 Mo Tu We Th Fr Sa Su 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
Example outputCtrl+Enter to run

See also date

zodiac(day?: date) -> str

the Western star sign for a birthday (today without one)

1
zodiac(date("2000-01-01"))"♑ Capricorn"
Example outputCtrl+Enter to run

See also chinese_zodiac

chinese_zodiac(year: int|date) -> str

the Chinese zodiac element and animal for a year

It goes by the calendar year, so for a date in January or February before Lunar New Year it gives the next year’s sign

1
chinese_zodiac(2026)"Fire Horse"
2
chinese_zodiac(1984)"Wood Rat"
Example outputCtrl+Enter to run

See also zodiac

1
# Thanksgiving: 4th Thursday
2
date(2026, 11, 1).nth_weekday(4, "thu")2026-11-26
3
# Memorial Day: last Monday
4
date(2026, 5, 1).nth_weekday(-1, "mon")2026-05-25
5
# 3 business days later
6
date("2026-12-24").add_workdays(3)2026-12-29
7
# workdays in December
8
workdays(date("2026-12-01"), date("2026-12-31"))22
9
# skipping US holidays
10
date("2026-12-24").add_workdays(3, "US")2026-12-30
11
# this week's number, by the ISO standard
12
today.iso_week45
13
# what does this cron line mean?
14
cron("*/15 9-17 * * mon-fri")"every 15 minutes, during hours 9 through 17, on Monday through Friday"
15
# when does it run next?
16
"0 9 * * 1-5".next(3)[2026-11-05 09:00:00 -06:00, 2026-11-06 09:00:00 -06:00, 2026-11-09 09:00:00 -06:00]
17
# star sign and Chinese zodiac for a 1990 birthday
18
[zodiac(date("1990-08-10")), chinese_zodiac(1990)]["♌ Leo", "Metal Horse"]
Example outputCtrl+Enter to run

Example results generated on 2026-11-04. Ones using now, today or randomness will differ when you run them.