Date
Library of functions for the date type.
Functions
AddInterval
Adds an interval to a date.
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.
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.
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.
Date.Build(2022, 1, 15)
// Result:
// 15th January 2022
Day
Returns the day component of the date.
Date.Day(date: date)
Parameters
date
: The date from which the day component is extracted.
Returns
int
: The day component of the date.
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).
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.
Date.FromEpochDay(0)
// Result:
// 1970-01-01
Date.FromEpochDay(1000)
// Result:
// 1972-09-27
FromTimestamp
Builds a date from a timestamp.
Date.FromTimestamp(timestamp: timestamp)
Parameters
timestamp
: The timestamp to convert to date.
Returns
date
: The date value built from the given timestamp.
Date.FromTimestamp(Timestamp.Build(1975, 6, 23, 9, 30))
// Result:
// 1975-06-23
Month
Returns the month component of the date.
Date.Month(date: date)
Parameters
date
: The date from which the month component is extracted.
Returns
int
: The month component of the date.
Date.Month(Date.Build(1975, 6, 23))
// Result:
// 6
Now
Returns the current date.
Date.Now()
Returns
date
: The current date.
Parse
Parses a date from a string.
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.
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.
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.
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.
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.
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.
Date.Year(date: date)
Parameters
date
: The date from which the year component is extracted.
Returns
int
: The year component of the date.
Date.Year(Date.Build(1975, 6, 23))
// Result:
// 1975