Share

Get Time Difference

Definition: getTimeDifference(timeOne, timeTwo, inputUnit, outputUnit)
Description: Calculates the time difference between two time values in the desired time unit. The following time units are supported:
- Seconds
- Milliseconds
- Microseconds
- Minutes
- Hours
- Days
- Nanoseconds
Parameters: - timeone: An integer representing a starting time in a certain unit of time. Example: 915 minutes.
- timetwo: An integer representing an ending time in the same unit of time as timeOne. Example: 1050 minutes.
- inputUnit: The existing time unit of timeOne and timeTwo. This could be seconds, minutes, hours, days, or any other unit of time that can be measured.
- outputUnit: The time unit in which the difference must be reported.
Returns: Difference between timeOne and timeTwo in outputUnit units.

The following script calculates the difference between timeOne and timeTwo and returns the value in the required unit.

from io.hevo.api import Event
from io.hevo.api import TimeUtils


def transform(event):

    # Get properties from the Event #
    eventName = event.getEventName()
    properties = event.getProperties()
    timeOne = <time value1>
    timeTwo = <time value2x>
    inputUnit = "<input unit>"
    outputUnit = "<output unit>"
    properties['timeDifference'] = TimeUtils.getTimeDifference(timeOne, timeTwo, inputUnit, outputUnit)
    return event


Sample Transformation

The following script calculates the difference between timeOne and timeTwo and returns the time difference value in minutes.

from io.hevo.api import Event
from io.hevo.api import TimeUtils

def transform(event):

    # Get properties from the Event #
    eventName = event.getEventName()
    properties = event.getProperties()
    timeOne = 1046649600000
    timeTwo = 1046649700000
    inputUnit = "MILLISECONDS"
    outputUnit = "minutes"
    properties['timeDifference'] = TimeUtils.getTimeDifference(timeOne, timeTwo, inputUnit, outputUnit)
    return event

Sample Output

The time difference of 100000 minutes is displayed in the timeDifference field.

Create Events


Last updated on Jun 28, 2023

Tell us what went wrong

Skip to the section