Use the make_interval() function to return the interval based on the provided fields.
- Combinations of year and month fields with day and time fields are not supported.
- At least one argument must be provided in order to create interval type.
Optional Parameters
- years
- Specifies number of years.
- months
- Specifies number of months.
- weeks
- Specifies number of weeks.
- days
- Specifies number of days.
- hours
- Specifies number of hours.
- minutes
- Specifies number of minutes.
- seconds
- Specifies number of seconds (fractional seconds allowed).
Example setup
Load the data to run the example.
>>> load_example_data("teradataml", "make_interval_data")
Create a DataFrame on 'make_interval_data' table.
>>> df = DataFrame("make_interval_data")
>>> df
Output
months weeks days hours minutes seconds years 5 0 0 0 0 0 0.000 1 2 0 10 5 30 20.500 0 0 0 7 23 59 59.999 0 6 2 0 12 0 0.000
Example 1: Create YEAR TO MONTH interval with the values provided in 'years' and 'months' columns
>>> from teradataml.dataframe.functions import make_interval >>> res = df.assign(iv_ym = make_interval(years=df.year, months=df.month)) >>> res
Output
months weeks days hours minutes seconds iv_ym years 0 6 2 0 12 0 0.000 0-06 0 0 0 7 23 59 59.999 0-00 1 2 0 10 5 30 20.500 1-02 5 0 0 0 0 0 0.000 5-00
>>> res.tdtypes
Output
years INTEGER() months INTEGER() weeks INTEGER() days INTEGER() hours INTEGER() minutes INTEGER() seconds FLOAT() iv_ym INTERVAL_YEAR_TO_MONTH()
Example 2: Creating YEAR interval with a constant value
>>> res = df.assign(iv_year = make_interval(years=2)) >>> res
Output
months weeks days hours minutes seconds iv_year years 5 0 0 0 0 0 0.000 2-00 1 2 0 10 5 30 20.500 2-00 0 0 0 7 23 59 59.999 2-00 0 6 2 0 12 0 0.000 2-00
>>> res.tdtypes
Output
years INTEGER() months INTEGER() weeks INTEGER() days INTEGER() hours INTEGER() minutes INTEGER() seconds FLOAT() iv_year INTERVAL_YEAR()
Example 4: Create DAY TO SECOND interval with the values provided in 'weeks', 'days', 'hours', 'minutes' and 'seconds' columns
>>> res = df.assign(iv_d2s = make_interval(weeks=df.weeks, days=df.days, hours=df.hours, ... minutes=df.minutes, seconds=df.seconds)) >>> res
Output
months weeks days hours minutes seconds iv_d2s years 5 0 0 0 0 0 0.000 0 00:00:00.000000 1 2 0 10 5 30 20.500 10 05:30:20.500000 0 0 0 7 23 59 59.999 7 23:59:59.999000 0 6 2 0 12 0 0.000 14 12:00:00.000000
>>> res.tdtypes
Output
years INTEGER() months INTEGER() weeks INTEGER() days INTEGER() hours INTEGER() minutes INTEGER() seconds FLOAT() iv_d2s INTERVAL_DAY_TO_SECOND()