Skip to main content

Date

Library of functions for the date type.

Functions

AddInterval

Adds an interval to a date.

Syntax:
Date.AddInterval(date: date, interval: interval)
Parameters
  • date: Start date.

  • interval: interval to add.

Returns
  • timestamp: The timestamp resulting from adding the interval to the date.
Example:
let
d = Date.Build(2018, 1, 1),
i = Interval.Build(years = 1, months = 2, days = 3, hours = 9, minutes = 30)
in
Date.AddInterval(d, i)
// Result:
// 2019-03-04 09:30

Build

Builds a date value.

Syntax:
Date.Build(year: int, month: int, day: int)
Parameters
  • year: Year component of the date to build.

  • month: Month component of the date to build.

  • day: Day component of the date to build.

Returns
  • date: The date value built from the given components.
Example:
Date.Build(2022, 1, 15)
// Result:
// 15th January 2022

Day

Returns the day component of the date.

Syntax:
Date.Day(date: date)
Parameters
  • date: The date from which the day component is extracted.
Returns
  • int: The day component of the date.
Example:
Date.Day(Date.Build(1975, 6, 23))
// Result:
// 23

FromEpochDay

Builds a date by adding the number of days from 1970-01-01 (Unix epoch).

Syntax:
Date.FromEpochDay(epochDays: long)
Parameters
  • epochDays: The number of days since 1970-01-01 (Unix epoch).
Returns
  • date: The date value built from the given number of days.
Example:
Date.FromEpochDay(0)
// Result:
// 1970-01-01

Date.FromEpochDay(1000)
// Result:
// 1972-09-27

FromTimestamp

Builds a date from a timestamp.

Syntax:
Date.FromTimestamp(timestamp: timestamp)
Parameters
  • timestamp: The timestamp to convert to date.
Returns
  • date: The date value built from the given timestamp.
Example:
Date.FromTimestamp(Timestamp.Build(1975, 6, 23, 9, 30))
// Result:
// 1975-06-23

Month

Returns the month component of the date.

Syntax:
Date.Month(date: date)
Parameters
  • date: The date from which the month component is extracted.
Returns
  • int: The month component of the date.
Example:
Date.Month(Date.Build(1975, 6, 23))
// Result:
// 6

Now

Returns the current date.

Syntax:
Date.Now()
Returns
  • date: The current date.

Parse

Parses a date from a string.

Syntax:
Date.Parse(value: string, format: string)
Parameters
  • value: The string to convert to date.

  • format: The format of the date.

Returns
  • date: The date value built from the given string.
Example:
Date.Parse("2018-02-01", "yyyy-MM-dd")
// Result:
// 2018-02-01

Date.Parse("23 June 1975", "d MMMM yyyy")
// Result:
// 1975-06-23

Details

For more information about format strings see the Temporal templates documentation.

Subtract

Subtracts two dates.

Syntax:
Date.Subtract(date1: date, date2: date)
Parameters
  • date1: date to be subtracted (minuend).

  • date2: date to subtract (subtrahend).

Returns
  • interval: The interval between the two dates.
Example:
let
d1 = Date.Build(2019, 3, 4),
d2 = Date.Build(2018, 1, 1)
in
Date.Subtract(d1, d2)
// Result:
// interval: years=1, months=2, days=3

SubtractInterval

Subtracts an interval to a date.

Syntax:
Date.SubtractInterval(date: date, interval: interval)
Parameters
  • date: Start date.

  • interval: Interval to subtract.

Returns
  • timestamp: The timestamp resulting from subtracting the interval to the date.
Example:
let
d = Date.Build(2019, 3, 4),
i = Interval.Build(years = 1, months = 2, days = 3, hours = 9, minutes = 30)
in
Date.SubtractInterval(d, i)
// Result:
// 2018-01-01 00:00

Year

Returns the year component of the date.

Syntax:
Date.Year(date: date)
Parameters
  • date: The date from which the year component is extracted.
Returns
  • int: The year component of the date.
Example:
Date.Year(Date.Build(1975, 6, 23))
// Result:
// 1975