Skip to content

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 notation. These interchangeable forms allow flexibility in how you structure expressions.

diffTime(to: timestamp, from: timestamp): interval
(to: timestamp).diffTime(from: timestamp): interval

Arguments

NameTypeRequiredDescription
totimestamptrueThe timestamp to compare (typically the later time)
fromtimestamptrueThe 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
}
create time_taken_duration from diffTime(processing_start_time, processing_end_time)
create time_taken_duration from processing_start_time.diffTime(processing_end_time)

Output

{
  "processing_start_time": 1728636298,
  "processing_end_time": 1728636358,
  "time_taken_duration": "50s"
}