Share

Parse Date String to Date

Definition: parseDateStringToDate (dateString: str, dateFormat: str) → datetime.date
Description: Parses the existing date format and returns a Python date object.

The value is ingested in Hevo as a string. However, it is loaded to the Destination as a timestamp object, as indicated by the timestamp datatype in the Transformation output.
Parameters: - dateString: The date in string form. Example: 2023-03-02 13:30:30 PM.
- dateFormat: The existing format of the dateString argument. Example: yyyy-MM-dd HH:mm:ss a.
Returns: The parsed value as a timestamp object.

The following script takes a date string in a date format as arguments and returns a date object.

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


def transform(event):

    # Get properties from the Event #
    dateString = '<date and timestamp value>'
    formatOfDate = '<input date format>'
    properties['<dateObject>'] = TimeUtils.parseDateStringToDate( dateString, formatOfDate )
    return event


Sample Transformation

The following script transforms the date string into a timestamp object by utilizing the parseDateStringToDate( dateString, formatOfDate ) method, and returns the result in the new_formatted_date field.

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

def transform(event):

    # Get properties from the Event #
    dateString = '01/02/2019 09:00:00 AM'
    formatOfDate = 'MM/dd/yyyy hh:mm:ss a'
    properties['new_formatted_date'] = TimeUtils.parseDateStringToDate( dateString, formatOfDate )
    return event

Sample Output

The date string 01/02/2019 09:00:00 AM is converted to a timestamp object with value 15463872000000, and added in the new_formatted_date field.

Create Events


Last updated on Jun 28, 2023

Tell us what went wrong

Skip to the section