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.

Returns
  • timestamp: The timestamp with the interval added.
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)
// Result:
// 2019-03-04 09:30:00

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)
// Result:
// 2022-01-15 09:30:00

Timestamp.Build(2022, 1, 15, 9, 30, seconds = 20)
// Result:
// 2022-01-15 9:30:20

Timestamp.Build(2022, 1, 15, 9, 30, seconds = 20, millis = 10)
// Result:
// 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.
Returns
  • int: The day component of the timestamp.
Example:
Timestamp.Day(Timestamp.Build(1975, 6, 23, 9, 30))
// Result:
// 23

FromDate

Builds a timestamp from a date.

Syntax:
Timestamp.FromDate(date: date)
Parameters
  • date: The date to convert to timestamp.
Returns
  • timestamp: The timestamp value.
Example:
Timestamp.FromDate(Date.Build(1975, 6, 23))
// Result:
// 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).
Returns
  • timestamp: The timestamp corresponding to the Unix epoch.
Example:
Timestamp.FromUnixTimestamp(1517443320)
// Result:
// 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.
Returns
  • int: The hours component of the timestamp.
Example:
Timestamp.Hour(Timestamp.Build(1975, 6, 23, 9, 30))
// Result:
// 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.
Returns
  • int: The milliseconds component of the timestamp.
Example:
Timestamp.Millis(Timestamp.Build(1975, 6, 23, 9, 30, seconds = 15, millis = 123)) // 123
// Result:
// 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.
Returns
  • int: The minutes component of the timestamp.
Example:
Timestamp.Minute(Timestamp.Build(1975, 6, 23, 9, 30))
// Result:
// 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.
Returns
  • int: The month component of the timestamp.
Example:
Timestamp.Month(Timestamp.Build(1975, 6, 23, 9, 30))
// Result:
// 6

Now

Returns the current timestamp.

Syntax:
Timestamp.Now()
Returns
  • timestamp: The current timestamp.
Example:
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.

Returns
  • timestamp: The timestamp value.
Example:
Timestamp.Parse("23/06/1975 09:30:15.123", "d/M/yyyy H:m:s.SSS")
// Result:
// 1975-06-23 09:30:15.123

Timestamp.Parse("9:30 23 June 1975", "H:m d MMMM yyyy")
// Result:
// 1975-06-23 09: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)).

Returns
  • collection(timestamp): The collection of timestamps.
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.
Returns
  • int: The seconds component of the timestamp.
Example:
Timestamp.Second(Timestamp.Build(1975, 6, 23, 9, 30, seconds = 15))
// Result:
// 15

Subtract

Subtracts two timestamps.

Syntax:
Timestamp.Subtract(timestamp1: timestamp, timestamp2: timestamp)
Parameters
  • timestamp1: Timestamp to be subtracted (minuend).

  • timestamp2: Timestamp to subtract (subtrahend).

Returns
  • interval: The interval between the two timestamps.
Example:
let
t1 = Timestamp.Build(2019, 3, 4, 9, 30),
t2 = Timestamp.Build(2018, 1, 1, 0, 0)
in
Timestamp.Subtract(t1, t2)
// Result:
// 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.

Returns
  • timestamp: The timestamp with the interval subtracted.
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)
// Result:
// 2018-01-01 00:00:00

TimeBucket

Truncates a timestamp to the specified precision.

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.

Returns
  • timestamp: The truncated timestamp.
Example:
Timestamp.TimeBucket(Interval.Build(millis = 100), Timestamp.Build(2007, 3, 14, 1, 2, seconds=3, millis=4))
// Result:
// 2007-03-14 01:02:03.000

Timestamp.TimeBucket(Interval.Build(years = 2), Timestamp.Build(2007, 3, 14, 1, 2, seconds=3, millis=4))
// Result:
// 2006-01-01 00:00:00

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

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

Valid string values for precision are:

  • milliseconds
  • second
  • minute
  • hour
  • day
  • week
  • month
  • quarter
  • year
  • decade
  • century
  • millennium.

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.
Returns
  • long: The Unix epoch corresponding to the timestamp.
Example:
Timestamp.ToUnixTimestamp(Timestamp.Build(2018, 2, 1, 1, 2))
// Result:
// 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.
Returns
  • int: The year component of the timestamp.
Example:
Timestamp.Year(Timestamp.Build(1975, 6, 23, 9, 30))
// Result:
// 1975