time
dates, durations, date math, relative text
Example results generated on 2026-10-08. Ones using
now,todayor randomness will differ when you run them: press Run on any example to run it in your browser, after editing it if you like.
types
# date
date("2026-12-25 18:30")
# → 2026-12-25 18:30:00 -06:00
# time of day: today at that time
9:30 + 45 min
# → 2026-10-08 10:15:00 -05:00
# duration
1h30m
# → 90 min
names
# now today tomorrow yesterday
pretty
# long date: time always shown
pretty(date("2026-12-25"))
# → "Friday, December 25, 2026 at 12:00 AM"
# short date
pretty(date("2026-12-25 18:30"), "short")
# → "Dec 25, 2026, 6:30 PM"
# other zones add theirs
pretty(date("2026-12-25 18:30") to "Asia/Tokyo")
# → "Saturday, December 26, 2026 at 9:30 AM JST"
# long duration: up to 3 of d h min s
pretty(5000 s)
# → "1 h 23 min 20 s"
# short duration: up to 2
pretty(5000 s, "short")
# → "1 h 23 min"
operators
# date ± time
date("2026-01-31") + 1 mo
# → 2026-02-28
# date - date
date("2027-01-01") - date("2026-12-25")
# → 7 d
# "time" - "time"
"17:00" - "08:45"
# → 8.25 h
# date < date
yesterday < now
# → true
conversions
# to unix, to unix_ms
date("2026-12-25") to unix
# → 1798178400
# to date
"2026-12-25" to date
# → 2026-12-25
Submodules
| module | about |
|---|---|
| calendars | periods, weekdays, business days, week numbers, month grids, cron, zodiacs |
| zones | the same moment in UTC, local time, any IANA zone or a city; world clocks |
| sky | sunrise, sunset, day length and moon phase for a place and date |
Functions
| function | description |
|---|---|
date(s: str) / date(s: str, fmt: str) / date(y: int, m: int, d: int, h?: int, min?: int, s?: int) / date(unix: int) | parse ISO, US (12/25/2026), written (Dec 25 2026) or natural language dates |
year(d: date) | year of a date |
month(d: date) | month of a date (1-12) |
day(d: date) | day of the month |
hour(d: date) | hour of a date |
minute(d: date) | minute of a date |
second(d: date) | second of a date |
weekday(d: date) | day name |
format(d: date, fmt: str) / format(fmt: str, args?: any, ...) | format a date with strftime codes, or numbers printf-style |
with(d: date, fields: map) | same date with fields replaced: year month day hour minute second |
is_weekend(d: date) | Saturday or Sunday |
is_weekday(d: date) | Monday through Friday |
is_today(d: date) | same calendar day as now |
is_past(d: date) | before now |
is_future(d: date) | after now |
age(d: date) | whole years since d |
diff(a: date, b: date) | calendar difference from a to b |
relative(d: date) | “in 3 days”, “2 hours ago” |
parts(duration: quantity) | duration in up to three of d, h, min, s; or to d h min for chosen units |
unix(d: date) | seconds since 1970-01-01 UTC; same as d to unix |
unix_ms(d: date) | milliseconds since 1970-01-01 UTC; same as d to unix_ms |
date_ms(ms: int) | the date from Unix milliseconds, as JavaScript and Java give them |
timeit(f: fn) | how long calling f takes |
stopwatch() | time since the last stopwatch() call (0 s the first time) |
date
date(s: str) / date(s: str, fmt: str) / date(y: int, m: int, d: int, h?: int, min?: int, s?: int) / date(unix: int): parse ISO, US (12/25/2026), written (Dec 25 2026) or natural language dates
date("2026-12-25")
# → 2026-12-25
date("next friday at 5pm")
# → 2026-10-09 17:00:00 -05:00
date("3 days ago")
# → 2026-10-05 07:58:47 -05:00
date("25.12.2026", "%d.%m.%Y")
# → 2026-12-25
date(2026, 12, 25, 18, 30)
# → 2026-12-25 18:30:00 -06:00
date(0)
# → 1969-12-31 18:00:00 -06:00
See also: format, with, start_of
year
year(d: date): year of a date
now.year
# → 2026
month
month(d: date): month of a date (1-12)
now.month
# → 10
day
day(d: date): day of the month
now.day
# → 8
hour
hour(d: date): hour of a date
now.hour
# → 7
minute
minute(d: date): minute of a date
now.minute
# → 58
second
second(d: date): second of a date
now.second
# → 47
weekday
weekday(d: date): day name
date("2026-12-25").weekday
# → "Friday"
format
format(d: date, fmt: str) / format(fmt: str, args?: any, ...): format a date with strftime codes, or numbers printf-style
now.format("%B %d, %Y")
# → "October 08, 2026"
now.format("%H:%M")
# → "07:58"
format("%5.2f%%", 12.345)
# → "12.35%"
with
with(d: date, fields: map): same date with fields replaced: year month day hour minute second
today.with({day: 1})
# → 2026-10-01
now.with({hour: 9, minute: 0})
# → 2026-10-08 09:00:47 -05:00
is_weekend
is_weekend(d: date): Saturday or Sunday
date("2026-10-10").is_weekend
# → true
See also: is_weekday, add_workdays
is_weekday
is_weekday(d: date): Monday through Friday
today.is_weekday
# → true
See also: is_weekend
is_today
is_today(d: date): same calendar day as now
now.is_today
# → true
tomorrow.is_today
# → false
See also: is_past
is_past
is_past(d: date): before now
yesterday.is_past
# → true
is_future
is_future(d: date): after now
tomorrow.is_future
# → true
See also: is_past
age
age(d: date): whole years since d
date("1990-06-15").age
# → 36
See also: diff
diff
diff(a: date, b: date): calendar difference from a to b
diff(date("2025-08-03"), date("2026-10-06 04:00"))
# → "1 yr 2 mo 3 d 4 h"
See also: age, relative, parts
relative
relative(d: date): “in 3 days”, “2 hours ago”
date("2026-12-25").relative
# → "in 3 months"
(now - 3 h).relative
# → "3 hours ago"
parts
parts(duration: quantity): duration in up to three of d, h, min, s; or to d h min for chosen units
(date("2026-12-25") - date("2026-10-06 14:24")).parts
# → "79 d 10 h 36 min"
5000 s.parts
# → "1 h 23 min 20 s"
unix
unix(d: date): seconds since 1970-01-01 UTC; same as d to unix
date(0).unix
# → 0
date(86400) to unix
# → 86400
unix_ms
unix_ms(d: date): milliseconds since 1970-01-01 UTC; same as d to unix_ms
date(1).unix_ms
# → 1000
date_ms
date_ms(ms: int): the date from Unix milliseconds, as JavaScript and Java give them
date_ms(1798178400000) == date(1798178400)
# → true
timeit
timeit(f: fn): how long calling f takes
timeit(|| (1..1000).sum) < 1 s
# → true
See also: stopwatch
stopwatch
stopwatch(): time since the last stopwatch() call (0 s the first time)
stopwatch() >= 0 s
# → true
See also: timeit
More examples
time
# day of the week
date("2026-12-25").weekday
# → "Friday"
# month math clamps to the end
date("2026-01-31") + 1 mo
# → 2026-02-28
# plain-English dates
date("next friday")
# → 2026-10-09
# countdown
(date("2027-01-01") - now).parts
# → "84 d 17 h 1 min"
# relative time
(now - 3 h).relative
# → "3 hours ago"
# first of next month
(today + 1 mo).with({day: 1})
# → 2026-11-01
# months with a Friday the 13th
(1..=12).filter(|m| date(2026, m, 13).weekday == "Friday")
# → [2, 3, 11]
# from a Unix timestamp
date(1798178400)
# → 2026-12-25
# compact durations
1h30m + 2d4h
# → 3210 min
# hours worked
17:00 - 8:45
# → 8.25 h