Time Functions
Note
These functions can be used when working with and manipulating datetime values.
Many time functions take an option<datetime> in order to return certain values from a datetime such as its hours, minutes, day of the year, and so in. If no argument is present, the current datetime will be extracted and used. As such, all of the following function calls are valid and will not return an error.
| Function | Description |
|---|---|
time::ceil() | Rounds a datetime up to the next largest duration |
time::day() | Extracts the day as a number from a datetime or current datetime |
time::epoch | Constant datetime representing the UNIX epoch |
time::floor() | Rounds a datetime down by a specific duration |
time::format() | Outputs a datetime according to a specific format |
time::group() | Groups a datetime by a particular time interval |
time::hour() | Extracts the hour as a number from a datetime or current datetime |
time::max() | Returns the greatest datetime from an array |
time::maximum | Constant representing the greatest possible datetime |
time::micros() | Extracts the microseconds as a number from a datetime or current datetime |
time::millis() | Extracts the milliseconds as a number from a datetime or current datetime |
time::min() | Returns the least datetime from an array |
time::minimum | Constant representing the least possible datetime |
time::minute() | Extracts the minutes as a number from a datetime or current datetime |
time::month() | Extracts the month as a number from a datetime or current datetime |
time::nano() | Returns the number of nanoseconds since the UNIX epoch until a datetime or current datetime |
time::now() | Returns the current datetime |
time::round() | Rounds a datetime to the nearest multiple of a specific duration |
time::second() | Extracts the second as a number from a datetime or current datetime |
time::timezone() | Returns the current local timezone offset in hours |
time::unix() | Returns the number of seconds since the UNIX epoch |
time::wday() | Extracts the week day as a number from a datetime or current datetime |
time::week() | Extracts the week as a number from a datetime or current datetime |
time::yday() | Extracts the yday as a number from a datetime or current datetime |
time::year() | Extracts the year as a number from a datetime or current datetime |
time::is_leap_year() | Checks if given datetime is a leap year |
time::from_micros() | Calculates a datetime based on the microseconds since January 1, 1970 0:00:00 UTC. |
time::from_millis() | Calculates a datetime based on the milliseconds since January 1, 1970 0:00:00 UTC. |
time::from_nanos() | Calculates a datetime based on the nanoseconds since January 1, 1970 0:00:00 UTC. |
time::from_secs() | Calculates a datetime based on the seconds since January 1, 1970 0:00:00 UTC. |
time::from_unix() | Calculates a datetime based on the seconds since January 1, 1970 0:00:00 UTC. |
time::from_ulid() | Calculates a datetime based on the ULID. |
time::from_uuid() | Calculates a datetime based on the UUID. |
time::set_year() | Sets the year value of a datetime. |
time::set_month() | Sets the year value of a datetime. |
time::set_day() | Sets the year value of a datetime. |
time::set_hour() | Sets the year value of a datetime. |
time::set_minute() | Sets the year value of a datetime. |
time::set_second() | Sets the year value of a datetime. |
time::set_nanosecond() | Sets the year value of a datetime. |
time::ceil
The time::ceil function rounds a datetime up to the next largest duration.
The following example shows this function, and its output, when used in a RETURN statement:
time::day
The time::day function extracts the day as a number from a datetime, or from the current date if no datetime argument is present.
The following example shows this function, and its output, when used in a RETURN statement:
time::epoch
The time::epoch constant returns the datetime for the UNIX epoch (January 1, 1970).
time::floor
The time::floor function rounds a datetime down by a specific duration.
The following example shows this function, and its output, when used in a RETURN statement:
time::format
The time::format function outputs a datetime as a string according to a specific format.
The following example shows this function, and its output, when used in a RETURN statement:
time::group
The time::group function reduces and rounds a datetime down to a particular time interval.
The following example shows this function, and its output, when used in a RETURN statement:
time::hour
The time::hour function extracts the hour as a number from a datetime, or from the current date if no datetime argument is present.
The following example shows this function, and its output, when used in a RETURN statement:
time::max
The time::max function returns the greatest datetime from an array of datetimes.
The following example shows this function, and its output, when used in a RETURN statement:
See also:
array::max, which extracts the greatest value from an array of valuesmath::max, which extracts the greatest number from an array of numbers
time::maximum
The time::maximum constant returns the greatest possible datetime that can be used.
Some examples of the constant in use:
time::micros
The time::micros function extracts the microseconds as a number from a datetime, or from the current date if no datetime argument is present.
The following example shows this function, and its output, when used in a RETURN statement:
time::millis
The time::millis function extracts the milliseconds as a number from a datetime, or from the current date if no datetime argument is present.
The following example shows this function, and its output, when used in a RETURN statement:
time::min
The time::min function returns the least datetime from an array of datetimes.
The following example shows this function, and its output, when used in a RETURN statement:
See also:
array::min, which extracts the least value from an array of valuesmath::min, which extracts the least number from an array of numbers
time::minimum
The time::minimum constant returns the least possible datetime that can be used.
Some examples of the constant in use:
time::minute
The time::minute function extracts the minutes as a number from a datetime, or from the current date if no datetime argument is present.
The following example shows this function, and its output, when used in a RETURN statement:
time::month
The time::month function extracts the month as a number from a datetime, or from the current date if no datetime argument is present.
The following example shows this function, and its output, when used in a RETURN statement:
time::nano
The time::nanofunction returns a datetime as an integer representing the number of nanoseconds since the UNIX epoch until a datetime, or the current date if no datetime argument is present.
The following example shows this function, and its output, when used in a RETURN statement:
time::now
The time::now function returns the current datetime as an ISO8601 timestamp.
time::round
The time::round function rounds a datetime up by a specific duration.
The following example shows this function, and its output, when used in a RETURN statement:
time::second
The time::second function extracts the second as a number from a datetime, or from the current date if no datetime argument is present.
The following example shows this function, and its output, when used in a RETURN statement:
time::timezone
The time::timezone function returns the current local timezone offset in hours.
time::unix
The time::unix function returns a datetime as an integer representing the number of seconds since the UNIX epoch until a certain datetime, or from the current date if no datetime argument is present.
The following example shows this function, and its output, when used in a RETURN statement:
time::wday
The time::wday function extracts the week day as a number from a datetime, or from the current date if no datetime argument is present.
The following example shows this function, and its output, when used in a RETURN statement:
time::week
The time::week function extracts the week as a number from a datetime, or from the current date if no datetime argument is present.
The following example shows this function, and its output, when used in a RETURN statement:
time::yday
The time::yday function extracts the day of the year as a number from a datetime, or from the current date if no datetime argument is present.
The following example shows this function, and its output, when used in a RETURN statement:
time::year
The time::year function extracts the year as a number from a datetime, or from the current date if no datetime argument is present.
The following example shows this function, and its output, when used in a RETURN statement:
time::is_leap_year()
The time::is_leap_year() function Checks if given datetime is a leap year.
The following example shows this function, and its output, when used in a RETURN statement:
time::from_micros
The time::from_micros function calculates a datetime based on the microseconds since January 1, 1970 0:00:00 UTC.
The following example shows this function, and its output, when used in a RETURN statement:
time::from_millis
The time::from_millis function calculates a datetime based on the milliseconds since January 1, 1970 0:00:00 UTC.
The following example shows this function, and its output, when used in a RETURN statement:
time::from_nanos
The time::from_nanos function calculates a datetime based on the nanoseconds since January 1, 1970 0:00:00 UTC.
The following example shows this function, and its output, when used in a RETURN statement:
time::from_secs
The time::from_secs function calculates a datetime based on the seconds since January 1, 1970 0:00:00 UTC.
The following example shows this function, and its output, when used in a RETURN statement:
time::from_unix
The time::from_unix function calculates a datetime based on the seconds since January 1, 1970 0:00:00 UTC.
The following example shows this function, and its output, when used in a RETURN statement:
time::from_ulid
The time::from_ulid function calculates a datetime based on the ULID.
The following example shows this function, and its output, when used in a RETURN statement:
As a ULID is only precise up to the millisecond, a conversion from a ULID to a timestamp will truncate nanosecond precision.
time::from_uuid
The time::from_uuid function calculates a datetime based on the UUID.
The following example shows this function, and its output, when used in a RETURN statement:
As a UUID is only precise up to the millisecond, a conversion from a UUID to a timestamp will truncate nanosecond precision.
time::set_year
The time::set_year function sets the year value of a datetime.
Example:
time::set_month
The time::set_month function sets the month value of a datetime.
Example:
time::set_day
The time::set_day function sets the day value of a datetime.
Example:
time::set_hour
The time::set_hour function sets the hour value of a datetime.
Example:
time::set_minute
The time::set_minute function sets the minute value of a datetime.
Example:
time::set_second
The time::set_second function sets the second value of a datetime.
Example:
time::set_nanosecond
The time::set_nanosecond function sets the nanosecond value of a datetime.
Example:
Since nanoseconds are not needed in a datetime, setting the nanoseconds of a datetime to 0 can be used to make a datetime look cleaner.