These functions can be used when converting between numeric and duration data.
| Function | Description |
|---|---|
duration::days() | Counts how many days fit in a duration |
duration::hours() | Counts how many hours fit in a duration |
duration::max | Constant representing the greatest possible duration |
duration::micros() | Counts how many microseconds fit in a duration |
duration::millis() | Counts how many milliseconds fit in a duration |
duration::mins() | Counts how many minutes fit in a duration |
duration::nanos() | Counts how many nanoseconds fit in a duration |
duration::secs() | Counts how many seconds fit in a duration |
duration::weeks() | Counts how many weeks fit in a duration |
duration::years() | Counts how many years fit in a duration |
duration::from_days() | Converts a numeric amount of days into a duration that represents days |
duration::from_hours() | Converts a numeric amount of hours into a duration that represents hours |
duration::from_micros() | Converts a numeric amount of microseconds into a duration that represents microseconds |
duration::from_millis() | Converts a numeric amount of milliseconds into a duration that represents milliseconds |
duration::from_mins() | Converts a numeric amount of minutes into a duration that represents minutes |
duration::from_nanos() | Converts a numeric amount of nanoseconds into a duration that represents nanoseconds |
duration::from_secs() | Converts a numeric amount of seconds into a duration that represents seconds |
duration::from_weeks() | Converts a numeric amount of weeks into a duration that represents weeks |
duration::daysThe duration::days function counts how many days fit into a duration.
API DEFINITIONduration::days(duration) -> number
The following example shows this function, and its output, when used in a RETURN statement:
RETURN duration::days(3w); 21
duration::hoursThe duration::hours function counts how many hours fit into a duration.
API DEFINITIONduration::hours(duration) -> number
The following example shows this function, and its output, when used in a RETURN statement:
RETURN duration::hours(3w); 504
duration::maxAvailable since: v2.3.0
The duration::max constant represents the greatest possible duration that can be used.
API DEFINITIONduration::max -> duration
Some examples of the constant in use:
duration::max; duration::max + 1ns; 100y IN 0ns..duration::max
Output-------- Query 1 -------- 584942417355y3w5d7h15s999ms999µs999ns -------- Query 2 -------- 'Failed to compute: "584942417355y3w5d7h15s999ms999µs999ns + 1ns", as the operation results in an arithmetic overflow.' -------- Query 3 -------- true
duration::microsThe duration::micros function counts how many microseconds fit into a duration.
API DEFINITIONduration::micros(duration) -> number
The following example shows this function, and its output, when used in a RETURN statement:
RETURN duration::micros(3w); 1814400000000
duration::millisThe duration::millis function counts how many milliseconds fit into a duration.
API DEFINITIONduration::millis(duration) -> number
The following example shows this function, and its output, when used in a RETURN statement:
RETURN duration::millis(3w); 1814400000
duration::minsThe duration::mins function counts how many minutes fit into a duration.
API DEFINITIONduration::mins(duration) -> number
The following example shows this function, and its output, when used in a RETURN statement:
RETURN duration::mins(3w); 30240
duration::nanosThe duration::nanos function counts how many nanoseconds fit into a duration.
API DEFINITIONduration::nanos(duration) -> number
The following example shows this function, and its output, when used in a RETURN statement:
RETURN duration::nanos(3w); 1814400000000000
duration::secsThe duration::secs function counts how many seconds fit into a duration.
API DEFINITIONduration::secs(duration) -> number
The following example shows this function, and its output, when used in a RETURN statement:
RETURN duration::secs(3w); 1814400
duration::weeksThe duration::weeks function counts how many weeks fit into a duration.
API DEFINITIONduration::weeks(duration) -> number
The following example shows this function, and its output, when used in a RETURN statement:
RETURN duration::weeks(3w); 3
duration::yearsThe duration::years function counts how many years fit into a duration.
API DEFINITIONduration::years(duration) -> number
The following example shows this function, and its output, when used in a RETURN statement:
RETURN duration::years(300w); 5
duration::from_daysThe duration::from_days function counts how many years fit into a duration.
API DEFINITIONduration::from_days(number) -> duration
The following example shows this function, and its output, when used in a RETURN statement:
RETURN duration::from_days(3); 3d
duration::from_hoursThe duration::from_hours function converts a numeric amount of hours into a duration that represents hours.
API DEFINITIONduration::from_hours(number) -> duration
The following example shows this function, and its output, when used in a RETURN statement:
RETURN duration::from_hours(3); 3h
duration::from_microsThe duration::from_micros function converts a numeric amount of microseconds into a duration that represents microseconds.
API DEFINITIONduration::from_micros(number) -> duration
The following example shows this function, and its output, when used in a RETURN statement:
RETURN duration::from_micros(3); 3μs
duration::from_millisThe duration::from_millis function converts a numeric amount of milliseconds into a duration that represents milliseconds.
API DEFINITIONduration::from_millis(number) -> duration
The following example shows this function, and its output, when used in a RETURN statement:
RETURN duration::from_millis(3); 3ms
duration::from_minsThe duration::from_mins function converts a numeric amount of minutes into a duration that represents minutes.
API DEFINITIONduration::from_mins(number) -> duration
The following example shows this function, and its output, when used in a RETURN statement:
RETURN duration::from_mins(3); 3m
duration::from_nanosThe duration::from_nanos function converts a numeric amount of nanoseconds into a duration that represents nanoseconds.
API DEFINITIONduration::from_nanos(number) -> duration
The following example shows this function, and its output, when used in a RETURN statement:
RETURN duration::from_nanos(3); 3ns
duration::from_secsThe duration::from_secs function converts a numeric amount of seconds into a duration that represents seconds.
API DEFINITIONduration::from_secs(number) -> duration
The following example shows this function, and its output, when used in a RETURN statement:
RETURN duration::from_secs(3); 3s
duration::from_weeksThe duration::from_weeks function converts a numeric amount of weeks into a duration that represents weeks.
API DEFINITIONduration::from_weeks(number) -> duration
The following example shows this function, and its output, when used in a RETURN statement:
RETURN duration::from_weeks(3); 3w
Available since: v2.0.0
Method chaining allows functions to be called using the . dot operator on a value of a certain type instead of the full path of the function followed by the value.
-- Traditional syntax duration::mins(2d6h); -- Method chaining syntax 2d6h.mins();
Response3240
This is particularly useful for readability when a function is called multiple times.
-- Traditional syntax duration::mins(duration::from_millis(98734234)); -- Method chaining syntax duration::from_millis(98734234).mins();
Response1645