otp.Operation.str.to_datetime#

to_datetime(format='%Y/%m/%d %H:%M:%S.%J', timezone=None)#

Converts the formatted time to the number of nanoseconds (datetime) since 1970/01/01 GMT.

Parameters
  • format (str) –

    The format might contain any characters, but the following combinations of characters have special meanings

    %Y - Year (4 digits)

    %y - Year (2 digits)

    %m - Month (2 digits)

    %d - Day of month (2 digits)

    %H - Hours (2 digits, 24-hour format)

    %I - Hours (2 digits, 12-hour format)

    %M - Minutes (2 digits)

    %S - Seconds (2 digits)

    %J - Nanoseconds (9 digits)

    %p - AM/PM (2 characters)

  • timezone (str | Operation | Column) – Timezone. The timezone of the query will be used if no timezone was passed.

Returns

nsectime Operation obtained from the string

Return type

Operation

Examples

>>> data = otp.Tick(X='5/17/22-11:10:56.123456789')
>>> data['Y'] = data['X'].str.to_datetime('%m/%d/%y-%H:%M:%S.%J', 'Europe/London')
>>> otp.run(data)
        Time                           X                             Y
0 2003-12-01  5/17/22-11:10:56.123456789 2022-05-17 06:10:56.123456789