time
dates and times: read them from text, do arithmetic with them, and show them in plain words
Dates and times. A date is a moment: a day and a time of day in a time zone. A duration is a length of time.
writing
Section titled “writing”Durations are quantities with a time unit, like 90 min, and units can run together: 1h30m.
good to know
Section titled “good to know”Dates typed without a zone are in your computer’s local time. today, tomorrow and yesterday are midnight at the start of those days. Months and years follow the calendar, so adding a month to January 31 gives the last day of February.
Tags: time
datea date from text: ISO (2026-12-25), US (12/25/2026), written out (Dec 25 2026) or plain English (next friday at 5pm, 3 days ago)yearthe year of a datemonththe month of a date, from 1 for January to 12daythe day of the month, from 1 to 31hourthe hour of a date, from 0 to 23minutethe minute of a date, from 0 to 59secondthe second of a date, from 0 to 59weekdaythe name of the day of the week, like “Friday”formata date as text laid out by strftime codes, such as %Y for the year, %m the month, %d the day, %H:%M the time and %B the month’s namewiththe same date with some parts changed, given as a map of year, month, day, hour, minute and second, like {day: 1}is_weekendwhether the date is a Saturday or Sundayis_weekdaywhether the date is Monday to Fridayis_todaywhether the date falls on today’s dateis_pastwhether the date is earlier than nowis_futurewhether the date is later than nowagehow many whole years have passed since d, as for someone’s age from their birthdaydiffthe time from a to b in calendar termsrelativehow far the date is from now, in words like “in 3 days” or “2 hours ago”partsa duration split into the largest units that fit, up to three of days, hours, minutes and secondshmsa duration as clock text, like 7:15:00, with hours that can pass 24unixthe Unix timestamp: seconds since the start of 1970 in UTC, the same asd to unixunix_msthe Unix timestamp in milliseconds, the same asd to unix_msdate_msthe date for a Unix timestamp in milliseconds, the form JavaScript and Java usetimeithow long it takes to call f, which takes no argumentsstopwatchthe time since stopwatch was last called (0 s the first time), for timing parts of a script
1# date: a moment, made with date() or now2date("2026-12-25 18:30")2026-12-25 18:30:00 -06:003# time of day: 9:30 means 9:30 today49:30 + 45 min2026-11-04 10:15:00 -06:005# duration: an amount of time61h30m90 minsyntax
Section titled “syntax”1# date + or - a duration moves it2date("2026-01-31") + 1 mo2026-02-283# date - date is the duration between4date("2027-01-01") - date("2026-12-25")7 d5# subtracting two times of day in quotes gives hours6"17:00" - "08:45"8.25 h7# < and > compare which is earlier8yesterday < nowtrue9# to unix: seconds since 1970 (UTC)10date("2026-12-25") to unix179817840011# to unix_ms does the same in milliseconds. Unix timestamps are how many systems store times12# to date reads a date from text13"2026-12-25" to date2026-12-25pretty
Section titled “pretty”1# a date, long: written out, time included2pretty(date("2026-12-25"))"Friday, December 25, 2026 at 12:00 AM"3# a date, short4pretty(date("2026-12-25 18:30"), "short")"Dec 25, 2026, 6:30 PM"5# a date not in local time names its zone6pretty(date("2026-12-25 18:30") to "Asia/Tokyo")"Saturday, December 26, 2026 at 9:30 AM JST"7# a duration, long: up to 3 of d, h, min and s8pretty(5000 s)"1 h 23 min 20 s"9# a duration, short: up to 2 of them10pretty(5000 s, "short")"1 h 23 min"Functions
Section titled “Functions”date(s: str) -> date / date(s: str, fmt: str) -> date / date(y: int, m: int, d: int, h: int = 0, min: int = 0, s: int = 0) -> date / date(y: int, m: int, d: int, calendar: str) -> date / date(unix: int) -> date
a date from text: ISO (2026-12-25), US (12/25/2026), written out (Dec 25 2026) or plain English (next friday at 5pm, 3 days ago)
Also from a format string with strftime codes, from year, month, day and optional time numbers, from year, month and day in another calendar (“hebrew”, “islamic”, “persian”, “julian”, “coptic”, “ethiopian” or “indian”), or from a Unix timestamp
1date("2026-12-25")2026-12-252date("next friday at 5pm")2026-11-06 17:00:00 -06:003date("3 days ago")2026-11-01 12:12:40 -06:004date("25.12.2026", "%d.%m.%Y")2026-12-255date(2026, 12, 25, 18, 30)2026-12-25 18:30:00 -06:006date(5787, 7, 1, "hebrew")2026-09-127date(1405, 1, 1, "persian")2026-03-218date(0)1969-12-31 18:00:00 -06:00See also format, with, start_of
year(d: date) -> int
the year of a date
1now.year2026month(d: date) -> int
the month of a date, from 1 for January to 12
1now.month11day(d: date) -> int
the day of the month, from 1 to 31
1now.day4hour(d: date) -> int
the hour of a date, from 0 to 23
1now.hour12minute
Section titled “minute”minute(d: date) -> int
the minute of a date, from 0 to 59
1now.minute12second
Section titled “second”second(d: date) -> int
the second of a date, from 0 to 59
1now.second40weekday
Section titled “weekday”weekday(d: date) -> str
the name of the day of the week, like “Friday”
1date("2026-12-25").weekday"Friday"format
Section titled “format”format(d: date, fmt: str) -> str / format(fmt: str, *args: any) -> str
a date as text laid out by strftime codes, such as %Y for the year, %m the month, %d the day, %H:%M the time and %B the month’s name
Given a format string first instead, formats numbers printf-style
1now.format("%B %d, %Y")"November 04, 2026"2now.format("%H:%M")"12:12"3format("%5.2f%%", 12.345)"12.35%"Tags: formatting
with(d: date, fields: map) -> date
the same date with some parts changed, given as a map of year, month, day, hour, minute and second, like {day: 1}
1today.with({day: 1})2026-11-012now.with({hour: 9, minute: 0})2026-11-04 09:00:40 -06:00is_weekend
Section titled “is_weekend”is_weekend(d: date) -> bool
whether the date is a Saturday or Sunday
1date("2026-10-10").is_weekendtrueSee also is_weekday, add_workdays
is_weekday
Section titled “is_weekday”is_weekday(d: date) -> bool
whether the date is Monday to Friday
1today.is_weekdaytrueSee also is_weekend
is_today
Section titled “is_today”is_today(d: date) -> bool
whether the date falls on today’s date
1now.is_todaytrue2tomorrow.is_todayfalseSee also is_past
is_past
Section titled “is_past”is_past(d: date) -> bool
whether the date is earlier than now
1yesterday.is_pasttrueis_future
Section titled “is_future”is_future(d: date) -> bool
whether the date is later than now
1tomorrow.is_futuretrueSee also is_past
age(d: date) -> int
how many whole years have passed since d, as for someone’s age from their birthday
1date("1990-06-15").age36See also diff
diff(a: date, b: date) -> str
the time from a to b in calendar terms
Years, months, days and smaller
1diff(date("2025-08-03"), date("2026-10-06 04:00"))"1 yr 2 mo 3 d 4 h"relative
Section titled “relative”relative(d: date) -> str
how far the date is from now, in words like “in 3 days” or “2 hours ago”
1date("2026-12-25").relative"in 2 months"2(now - 3 h).relative"3 hours ago"parts(duration: quantity) -> str
a duration split into the largest units that fit, up to three of days, hours, minutes and seconds
For units of your choice, write to h min
1(date("2026-12-25") - date("2026-10-06 14:24")).parts"79 d 10 h 36 min"25000 s.parts"1 h 23 min 20 s"hms(duration: quantity) -> str
a duration as clock text, like 7:15:00, with hours that can pass 24
Shows milliseconds when there are any
17.25 h to hms"7:15:00"2(90 min).hms"1:30:00"35000.5 s.hms"1:23:20.500"See also parts
unix(d: date) -> int
the Unix timestamp: seconds since the start of 1970 in UTC, the same as d to unix
1date(0).unix02date(86400) to unix86400unix_ms
Section titled “unix_ms”unix_ms(d: date) -> int
the Unix timestamp in milliseconds, the same as d to unix_ms
1date(1).unix_ms1000date_ms
Section titled “date_ms”date_ms(ms: int) -> date
the date for a Unix timestamp in milliseconds, the form JavaScript and Java use
1date_ms(1798178400000) == date(1798178400)truetimeit
Section titled “timeit”timeit(f: fn) -> quantity
how long it takes to call f, which takes no arguments
1timeit(|| (1..1000).sum) < 1 strueSee also stopwatch
stopwatch
Section titled “stopwatch”stopwatch() -> quantity
the time since stopwatch was last called (0 s the first time), for timing parts of a script
1stopwatch() >= 0 strueSee also timeit
More examples
Section titled “More examples”1# day of the week2date("2026-12-25").weekday"Friday"3# adding a month stops at the end of a shorter month4date("2026-01-31") + 1 mo2026-02-285# plain-English dates6date("next friday")2026-11-067# how long until new year8(date("2027-01-01") - now).parts"57 d 11 h 47 min"9# 3 hours ago, in words10(now - 3 h).relative"3 hours ago"11# first of next month12(today + 1 mo).with({day: 1})2026-12-0113# months with a Friday the 13th14(1..=12).filter(|m| date(2026, m, 13).weekday == "Friday")[2, 3, 11]15# a Unix timestamp as a date16date(1798178400)2026-12-2517# durations written without spaces181h30m + 2d4h3210 min19# hours worked from 8:45 to 17:002017:00 - 8:458.25 hExample results generated on 2026-11-04. Ones using now, today or randomness will differ when you run them.