Teradata Package for Python Function Reference on VantageCloud Lake - to_interval - Teradata Package for Python - Look here for syntax, methods and examples for the functions included in the Teradata Package for Python.

Teradata® Package for Python Function Reference on VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Package for Python
Release Number
20.00.00.11
Publication Date
August 2026
Content Type
Programming Reference
Publication ID
B700-4500-200K
ft:locale
en-US
ft:lastEdition
2026-08-13
ft:sourceId
FTML
dita:id
TeradataPython_FxRef_Lake_2000
Product Category
Teradata Vantage
teradataml.dataframe.sql.DataFrameColumn.to_interval = to_interval(self, value=None, type_=<class 'teradatasqlalchemy.types.INTERVAL_DAY_TO_SECOND'>)
DESCRIPTION:
    Converts a numeric value or string value into an INTERVAL_DAY_TO_SECOND or INTERVAL_YEAR_TO_MONTH value.
 
PARAMETERS:
    value:
        Optional, when column type is VARCHAR or CHAR, otherwise required.
        Specifies the unit of value for numeric value.
        when type_ is INTERVAL_DAY_TO_SECOND permitted values:
            * DAY, HOUR, MINUTE, SECOND
        when type_ is INTERVAL_YEAR_TO_MONTH permitted values:
            * YEAR, MONTH
        Note:
            * Permitted Values are case insensitive.
        Type: str or ColumnExpression
 
    type_:
        Optional Argument.
        Specifies a teradatasqlalchemy type or an object of a teradatasqlalchemy type
        that the column needs to be cast to.
        Default value: TIMESTAMP
        Permitted Values: INTERVAL_DAY_TO_SECOND or INTERVAL_YEAR_TO_MONTH type.
        Types: teradatasqlalchemy type or object of teradatasqlalchemy type
 
Returns:
    ColumnExpression
 
EXAMPLES:
    # Load the data to run the example.
    >>> load_example_data("teradataml", "interval_data")
 
    # Create a DataFrame on 'interval_data' table.
    >>> df = DataFrame("interval_data")
    >>> df
    id  int_col value_col value_col1        str_col1 str_col2
    2      657    MINUTE      MONTH           PT73H    -P14M
    3     1234    SECOND      MONTH    100 04:23:59    06-10
    1      240      HOUR       YEAR  P100DT4H23M59S  P100Y4M
    0       20       DAY       YEAR    100 04:23:59    04-10
 
    >>> df.tdtypes
    id                                      INTEGER()
    int_col                                  BIGINT()
    value_col     VARCHAR(length=30, charset='LATIN')
    value_col1    VARCHAR(length=30, charset='LATIN')
    str_col1      VARCHAR(length=30, charset='LATIN')
    str_col2      VARCHAR(length=30, charset='LATIN')
 
    # Example 1: Convert "int_col" column to INTERVAL_DAY_TO_SECOND with value
    #            provided in "value_col".
    >>> df.assign(col = df.int_col.to_interval(df.value_col))
    id  int_col value_col value_col1        str_col1 str_col2                    col
    2      657    MINUTE      MONTH           PT73H    -P14M      0 10:57:00.000000
    3     1234    SECOND      MONTH    100 04:23:59    06-10      0 00:20:34.000000
    1      240      HOUR       YEAR  P100DT4H23M59S  P100Y4M     10 00:00:00.000000
    0       20       DAY       YEAR    100 04:23:59    04-10     20 00:00:00.000000
 
    # Example 2: Convert int_col to INTERVAL_YEAR_TO_MONTH when value = 'MONTH'.
    >>> df.assign(col = df.int_col.to_interval('MONTH', INTERVAL_YEAR_TO_MONTH))
    id  int_col value_col value_col1        str_col1 str_col2       col
    2      657    MINUTE      MONTH           PT73H    -P14M     54-09
    3     1234    SECOND      MONTH    100 04:23:59    06-10    102-10
    1      240      HOUR       YEAR  P100DT4H23M59S  P100Y4M     20-00
    0       20       DAY       YEAR    100 04:23:59    04-10      1-08
 
    # Example 3: Convert string column "str_col1" to INTERVAL_DAY_TO_SECOND.
    >>> df.assign(col = df.str_col1.to_interval())
    id  int_col value_col value_col1        str_col1 str_col2                    col
    2      657    MINUTE      MONTH           PT73H    -P14M      3 01:00:00.000000
    3     1234    SECOND      MONTH    100 04:23:59    06-10    100 04:23:59.000000
    1      240      HOUR       YEAR  P100DT4H23M59S  P100Y4M    100 04:23:59.000000
    0       20       DAY       YEAR    100 04:23:59    04-10    100 04:23:59.000000
 
    # Example 4: Convert string column "str_col2" to INTERVAL_DAY_TO_MONTH.
    >>> df.assign(col = df.str_col2.to_interval(type_=INTERVAL_YEAR_TO_MONTH))
    id  int_col value_col value_col1        str_col1 str_col2       col
    2      657    MINUTE      MONTH           PT73H    -P14M     -1-02
    3     1234    SECOND      MONTH    100 04:23:59    06-10      6-10
    1      240      HOUR       YEAR  P100DT4H23M59S  P100Y4M    100-04
    0       20       DAY       YEAR    100 04:23:59    04-10      4-10