Skip to main content

Timestamp

Library of functions for the timestamp type.

Functions

AddInterval

Adds an interval to a timestamp.

Syntax:
Timestamp.AddInterval(timestamp: timestamp, interval: interval)
Parameters
  • timestamp: Start timestamp.
  • interval: interval to add.
Example:
let
t = Timestamp.Build(2018, 1, 1, 0, 0),
i = Interval.Build(years = 1, months = 2, days = 3, hours = 9, minutes = 30)
in
Timestamp.AddInterval(t, i) // 2019-03-04 09:30

Build

Builds a timestamp value

Syntax:
Timestamp.Build(year: int, month: int, day: int, hours: int, minutes: int, seconds: optional int, millis: optional int)
Parameters
  • year: Year component of the timestamp to build.
  • month: Month component of the timestamp to build.
  • day: Day component of the timestamp to build.
  • hours: Hours component of the timestamp to build.
  • minutes: Minutes component of the timestamp to build.
  • seconds: Seconds component of the timestamp to build.
  • millis: Milliseconds component of the timestamp to build.
Example:
Timestamp.Build(2022, 1, 15, 9, 30) // 2022-01-15 09:30:00
Timestamp.Build(2022, 1, 15, 9, 30, seconds = 20) // 2022-01-15 9:30:20
Timestamp.Build(2022, 1, 15, 9, 30, seconds = 20, millis = 10) //2022-01-15 9:30:20.010

Day

Returns the day component of the timestamp.

Syntax:
Timestamp.Day(timestamp: timestamp)
Parameters
  • timestamp: The timestamp from which the day component is extracted.
Example:
Timestamp.Day(Timestamp.Build(1975, 6, 23, 9, 30)) // 23

FromDate

Builds a timestamp from a date.

Syntax:
Timestamp.FromDate(date: date)
Parameters
  • date: The date to convert to timestamp.
Example:
Timestamp.FromDate(Date.Build(1975, 6, 23)) // 1975-06-23 00:00:00 

FromUnixTimestamp

Builds a timestamp from a Unix epoch (number of seconds since 01-01-1970).

Syntax:
Timestamp.FromUnixTimestamp(epoch: long)
Parameters
  • epoch: Unix epoch (number of seconds since 01-01-1970).
Example:
Timestamp.FromUnixTimestamp(1517443320) //  2018-02-1 01:02:00

Hour

Returns the hours component of the timestamp.

Syntax:
Timestamp.Hour(timestamp: timestamp)
Parameters
  • timestamp: The timestamp from which the hours component is extracted.
Example:
Timestamp.Hour(Timestamp.Build(1975, 6, 23, 9, 30)) // 9

Millis

Returns the milliseconds component of the timestamp.

Syntax:
Timestamp.Millis(timestamp: timestamp)
Parameters
  • timestamp: The timestamp from which the year milliseconds is extracted.
Example:
Timestamp.Millis(Timestamp.Build(1975, 6, 23, 9, 30, seconds = 15, millis = 123)) // 123

Minute

Returns minutes part of the timestamp as an integer.

Syntax:
Timestamp.Minute(timestamp: timestamp)
Parameters
  • timestamp: The timestamp from which the minutes component is extracted.
Example:
Timestamp.Minute(Timestamp.Build(1975, 6, 23, 9, 30)) // 30

Month

Returns the month component of the timestamp.

Syntax:
Timestamp.Month(timestamp: timestamp)
Parameters
  • timestamp: The timestamp from which the month component is extracted.
Example:
Timestamp.Month(Timestamp.Build(1975, 6, 23, 9, 30)) // 6

Now

Returns the current timestamp.

Syntax:
Timestamp.Now()

Parse

Parses a timestamp from a string.

Syntax:
Timestamp.Parse(value: string, format: string)
Parameters
  • value: The string to convert to timestamp.
  • format: The format of the timestamp.
Example:
Timestamp.Parse("23/06/1975 09:30:15.123", "d/M/yyyy H:m:s.SSS") // 1975-06-23T09:30:15.123
Timestamp.Parse("9:30 23 June 1975", "H:m d MMMM yyyy") // 1975-06-23T09:30:00

Details

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

Range

Builds a collection of timestamps between two specified timestamps.

Syntax:
Timestamp.Range(start: timestamp, end: timestamp, step: optional interval)
Parameters
  • start: The starting value.
  • end: The end value (not included).
  • step: The step value (default: Interval.Build(days=1)).
Example:
Timestamp.Range(Timestamp.Build(1975, 6, 23, 9, 30), Timestamp.Build(1975, 6, 28, 9, 30), step=Interval.Build(days=2))

Second

Returns the seconds component of the timestamp.

Syntax:
Timestamp.Second(timestamp: timestamp)
Parameters
  • timestamp: The timestamp from which the seconds component is extracted.
Example:
Timestamp.Second(Timestamp.Build(1975, 6, 23, 9, 30, seconds = 15)) // 15

Subtract

Subtracts two timestamps.

Syntax:
Timestamp.Subtract(timestamp1: timestamp, timestamp2: timestamp)
Parameters
  • timestamp1: Timestamp to be subtracted (minuend).
  • timestamp2: Timestamp to subtract (subtrahend).
Example:
let
t1 = Timestamp.Build(2019, 3, 4, 9, 30),
t2 = Timestamp.Build(2018, 1, 1, 0, 0)
in
Timestamp.Subtract(t1, t2) // interval: years=1, months=2, days=3, hours=9, minutes=30

SubtractInterval

Subtracts an interval to a timestamp.

Syntax:
Timestamp.SubtractInterval(timestamp: timestamp, interval: interval)
Parameters
  • timestamp: Start timestamp.
  • interval: Interval to subtract.
Example:
let
t = Timestamp.Build(2019, 3, 4, 9, 30),
i = Interval.Build(years = 1, months = 2, days = 3, hours = 9, minutes = 30)
in
Timestamp.Subtract(t, i) // 2018-01-01 00:00

TimeBucket

Truncates a timestamp to the specified precision.

Valid string values for precision are:

  • milliseconds
  • second
  • minute
  • hour
  • day
  • week
  • month
  • quarter
  • year
  • decade
  • century
  • millennium
Syntax:
Timestamp.TimeBucket(value: interval or string, timestamp.: timestamp)
Parameters
  • value: Interval or string definition to which the timestamp will be truncated.
  • timestamp.: The timestamp to truncate.
Example:
Timestamp.TimeBucket(Interval.Build(millis = 100), Timestamp.Build(2007, 3, 14, 1, 2, seconds = 3, millis =4 )) // "2007-03-14 01:02:03.000"
Timestamp.TimeBucket(Interval.Build(years = 2), Timestamp.Build(2007, 3, 14, 1, 2, seconds = 3, millis =4 )) // "2006-01-01 00:00:00"

Timestamp.TimeBucket("hour", Timestamp.Build(2007, 3, 14, 1, 2, seconds = 3, millis =4 )) // "2007-03-14 01:00:00"
Timestamp.TimeBucket("year", Timestamp.Build(2007, 3, 14, 1, 2, seconds = 3, millis =4 )) // "2007-01-01 00:00:00"


ToUnixTimestamp

Converts a timestamp into the corresponding Unix epoch (number of seconds since 01-01-1970).

Syntax:
Timestamp.ToUnixTimestamp(timestamp: timestamp)
Parameters
  • timestamp: Timestamp to convert to Unix epoch.
Example:
Timestamp.ToUnixTimestamp(Timestamp.Build(2018, 2, 1, 1, 2)) // 1517443320

Year

Returns the year component of the timestamp.

Syntax:
Timestamp.Year(timestamp: timestamp)
Parameters
  • timestamp: The timestamp from which the year component is extracted.
Example:
Timestamp.Year(Timestamp.Build(1975, 6, 23, 9, 30)) // 1975