Skip to content

Date functions

Every function in this family, with its signature and examples. Each example runs as a test of the language. See Language basics for how calls, types, and operators work.

now

Returns the current date and time.

now() → date
  • now() gives @August 30, 2023 5:55 PM

today

Returns the current date without the time.

today() → date
  • today() gives @August 30, 2023

minute

Returns the minute of the date (0-59).

minute(date: date) → number

Also callable as receiver.minute(…), with the receiver as the first argument.

  • minute(parseDate("2023-07-10T17:35Z")) gives 35

hour

Returns the hour of the date (0-23).

hour(date: date) → number

Also callable as receiver.hour(…), with the receiver as the first argument.

  • hour(parseDate("2023-07-10T17:35Z")) gives 17

day

Returns the day of the week of the date, between 1 (Monday) and 7 (Sunday).

day(date: date) → number

Also callable as receiver.day(…), with the receiver as the first argument.

  • day(parseDate("2023-07-10T17:35Z")) gives 1

date

Returns the day of the month from the date (1-31).

date(date: date) → number

Also callable as receiver.date(…), with the receiver as the first argument.

  • date(parseDate("2023-07-10T17:35Z")) gives 10

week

Returns the ISO week of the year of the date (1-53).

week(date: date) → number

Also callable as receiver.week(…), with the receiver as the first argument.

  • week(parseDate("2023-01-02")) gives 1

month

Returns the month of the date (1-12).

month(date: date) → number

Also callable as receiver.month(…), with the receiver as the first argument.

  • month(parseDate("2023-07-10T17:35Z")) gives 7

year

Returns the year of the date.

year(date: date) → number

Also callable as receiver.year(…), with the receiver as the first argument.

  • year(now()) gives 2023

dateAdd

Adds time to the date; the unit is "years", "quarters", "months", "weeks", "days", "hours" or "minutes".

dateAdd(date: date, amount: number, unit: text) → date

Also callable as receiver.dateAdd(…), with the receiver as the first argument.

  • dateAdd(now(), 1, "days") gives @August 31, 2023 5:55 PM
  • dateAdd(now(), 2, "months") gives @October 30, 2023 5:55 PM
  • dateAdd(now(), 3, "years") gives @August 30, 2026 5:55 PM

dateSubtract

Subtracts time from the date; the unit is "years", "quarters", "months", "weeks", "days", "hours" or "minutes".

dateSubtract(date: date, amount: number, unit: text) → date

Also callable as receiver.dateSubtract(…), with the receiver as the first argument.

  • dateSubtract(now(), 1, "days") gives @August 29, 2023 5:55 PM
  • dateSubtract(now(), 2, "months") gives @June 30, 2023 5:55 PM
  • dateSubtract(now(), 3, "years") gives @August 30, 2020 5:55 PM

dateBetween

Returns the difference between two dates as whole units, first date minus second, truncated toward zero.

dateBetween(date: date, other: date, unit: text) → number

Also callable as receiver.dateBetween(…), with the receiver as the first argument.

  • dateBetween(now(), parseDate("2022-09-07"), "days") gives 357
  • dateBetween(parseDate("2030-01-01"), now(), "years") gives 6

dateRange

Returns the date range from a start date to an end date, as the two-item list [start, end]; dateStart() and dateEnd() read its ends.

dateRange(start: date, end: date) → list<date>

Also callable as receiver.dateRange(…), with the receiver as the first argument.

  • dateRange(parseDate("2023-07-10"), parseDate("2023-07-20")) gives [@July 10, 2023, @July 20, 2023]

dateStart

Returns the start of a date range; a plain date is its own start.

dateStart(range: list<date>) → date
dateStart(date: date) → date

Also callable as receiver.dateStart(…), with the receiver as the first argument.

  • dateStart(dateRange(parseDate("2023-07-10"), parseDate("2023-07-20"))) gives @July 10, 2023
  • dateStart(now()) gives @August 30, 2023 5:55 PM

dateEnd

Returns the end of a date range; a plain date is its own end.

dateEnd(range: list<date>) → date
dateEnd(date: date) → date

Also callable as receiver.dateEnd(…), with the receiver as the first argument.

  • dateEnd(dateRange(parseDate("2023-07-10"), parseDate("2023-07-20"))) gives @July 20, 2023

timestamp

Returns the Unix timestamp of the date: the milliseconds elapsed since January 1, 1970 UTC.

timestamp(date: date) → number

Also callable as receiver.timestamp(…), with the receiver as the first argument.

  • timestamp(now()) gives 1693418100000

fromTimestamp

Returns the date from the given Unix timestamp in milliseconds.

fromTimestamp(timestamp: number) → date

Also callable as receiver.fromTimestamp(…), with the receiver as the first argument.

  • fromTimestamp(1689024900000) gives @July 10, 2023 9:35 PM

parseDate

Returns the date parsed according to the ISO 8601 standard, in UTC; with a format, parsed with the Moment tokens YYYY, YY (00-68 is 2000-2068), MMMM, MMM, MM, M, DD, D, Do, dddd, ddd, HH, H, hh, h (with A or a), mm, m, ss, s, SSS, A, a and [literal] text. The format needs the year; a missing month or day is the first, a missing time is midnight. Text that does not match the format fails the run.

parseDate(text: text) → date
parseDate(text: text, format: text) → date

Also callable as receiver.parseDate(…), with the receiver as the first argument.

  • parseDate("2022-01-01") gives @January 1, 2022
  • parseDate("2022-01-01T00:00Z") gives @January 1, 2022
  • parseDate("30/09/2026", "DD/MM/YYYY") gives @September 30, 2026
  • parseDate("30 Sep 2026 5:55 PM", "D MMM YYYY h:mm A") gives @September 30, 2026 5:55 PM

formatDate

Formats the date with Moment tokens: YYYY, YY, Y (year), Q (quarter), MMMM, MMM, MM, M (month), DD, D, Do (day of month), DDDD, DDD (day of year), dddd, ddd, dd, d (weekday; d is 0 for Sunday), E (ISO weekday), WW, W (ISO week), HH, H (hour 0-23), hh, h (hour 1-12), mm, m (minute), ss, s (second), SSS (millisecond), A, a (AM/PM, am/pm), Z, ZZ (offset), X, x (Unix seconds, milliseconds). Text in [brackets] is written as is; any other letter is an error.

formatDate(date: date, format: text) → text

Also callable as receiver.formatDate(…), with the receiver as the first argument.

  • formatDate(now(), "MMMM D, Y") gives "August 30, 2023"
  • formatDate(now(), "MM/DD/YYYY") gives "08/30/2023"
  • formatDate(now(), "h:mm A") gives "5:55 PM"