Share

Convert Epoch to Required Format

Definition: fromEpochToFormattedDate(epoch: int, requiredFormat: str) → str
Description: Converts an epoch value in milliseconds to a date format of your choice.
Parameters: - epoch: The timestamp in milliseconds.
- requiredFormat: The format to which the epoch timestamp must be converted. Example: MM/dd/yyyy hh:mm:ss a.
Returns: The converted value as a formatted date string.

The following script takes a date value as an argument and returns the date in the specified format.

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


def transform(event):

    # Get properties from the Event #
    epoch = <epoch value>
    requiredFormat = '<MMMM d, yy. hh:mm a>'
    properties['<formattedDate>'] = TimeUtils.fromEpochToFormattedDate(epoch, requiredFormat)
    return event


Sample Transformation

The following script transforms the epoch time (in milliseconds) stored in the millis field into a varchar object by utilizing the fromEpochToFormattedDate(epoch, requiredFormat) method, and returns the result in the updated_formatted_date field.

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

def transform(event):

    # Get properties from the Event #
    epoch = 1672987516206
    requiredFormat = 'MMMM d, yy. hh:mm a'
    properties['updated_formatted_date'] = TimeUtils.fromEpochToFormattedDate(epoch, requiredFormat)
    return event

Sample Output

The epoch time 1672987516206 is converted to January 6, 23. 06:45 AM and added in the updated formatted_date field.

Create Events


Last updated on Jun 28, 2023

Tell us what went wrong

Skip to the section