diffTime
Description
Returns the duration between two timestamps as an interval.
The result is not the absolute difference:
- Positive if
to > from - Negative if
to < from
Syntax
Like many functions in DataPrime, diffTime supports two notations, function and method. These interchangeable forms allow flexibility in how you structure expressions.
- Function notation
- Method notation
diffTime(to: timestamp, from: timestamp): interval
(to: timestamp).diffTime(from: timestamp): interval
Arguments
| Name | Type | Required | Description |
|---|---|---|---|
to | timestamp | true | The timestamp to compare (typically the later time) |
from | timestamp | true | The timestamp to compare (typically the earlier time) |
Example
Use case: Measure process duration
A document contains start and end timestamps for a process. Use diffTime to compute the elapsed interval.
{
"processing_start_time": 1728636298,
"processing_end_time": 1728636358
}
Example query
- Function notation
- Method notation
create time_taken_duration from diffTime(processing_start_time, processing_end_time)
create time_taken_duration from processing_start_time.diffTime(processing_end_time)
Example output
{
"processing_start_time": 1728636298,
"processing_end_time": 1728636358,
"time_taken_duration": "50s"
}