Teradata Package for Python Function Reference | 20.00 - oadd_months - 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 - 20.00
- Deployment
- VantageCloud
- VantageCore
- Edition
- Enterprise
- IntelliFlex
- VMware
- Product
- Teradata Package for Python
- Release Number
- 20.00.00.03
- Published
- December 2024
- ft:locale
- en-US
- ft:lastEdition
- 2024-12-19
- dita:id
- TeradataPython_FxRef_Enterprise_2000
- lifecycle
- latest
- Product Category
- Teradata Vantage
- teradataml.dataframe.sql.DataFrameColumn.oadd_months = oadd_months(self, expression)
- DESCRIPTION:
Function adds an integer number of months, date or timestamp value in specified date or timestamp value in a
column as a literal.
PARAMETERS:
expression:
Optional Argument.
Specifies a date or timestamp value. If date_timestamp_value is NULL, NULL is returned.
Types: DataFrameColumn
Note:
1. Since TIMESTAMP values are stored in UTC time within the database and lack a time zone, the session
time zone is used to interpret the time stamp value within the function. For TIMESTAMP WITH TIME ZONE
values, the time zone component is used to interpret the time stamp value within the function.
2. If the day component of expression is the last day of the month, or if the resulting month
has fewer days than the day component of expression, oadd_months() returns the last day of
the resulting month. Otherwise, oadd_months() returns a value that has the same day component as
expression.
3. The difference between oadd_months() and add_months() is that if a month is added to an end-of-month
date in oadd_months(), the function always returns an end-of-month date.
expression:
Optional Argument.
Specifies the number of months to add. If expression is NULL, NULL is returned.
Types: integer
RAISES:
RAISES:
TypeError, ValueError, TeradataMlException
RETURNS:
DataFrameColumn
EXAMPLES:
# Load the data to run the example.
>>> load_example_data("dataframe", ["sales"])
# Create a DataFrame on 'sales' table.
>>> df = DataFrame.from_table('sales')
# Preparing the data.
>>> df_sales = df.assign(dates = case([(df.accounts == 'Alpha Co', df.datetime + random.randrange(20,1000,3)),
(df.accounts == 'Blue Inc', df.datetime + random.randrange(20,1000,3)),
(df.accounts == 'Jones LLC', df.datetime + random.randrange(20,1000,3)),
(df.accounts == 'Orange Inc', df.datetime + random.randrange(20,1000,3)),
(df.accounts == 'Yellow Inc', df.datetime + random.randrange(20,1000,3)),
(df.accounts == 'Red Inc', df.datetime + random.randrange(20,1000,3))]))
# Example 1: Adds an integer number of months, date or timestamp value in specified date or timestamp value in
# a column as a literal.
>>> df = df_sales.assign(res = df_sales.dates.oadd_months(2))
>>> print(df)
Feb Jan Mar Apr datetime dates res
accounts
Alpha Co 210.0 200.0 215.0 250.0 04/01/2017 18/03/20 2018-05-20
Blue Inc 90.0 50.0 95.0 101.0 04/01/2017 19/02/25 2019-04-25
Jones LLC 200.0 150.0 140.0 180.0 04/01/2017 17/04/27 2017-06-27
Orange Inc 210.0 NaN NaN 250.0 04/01/2017 19/05/29 2019-07-29
Yellow Inc 90.0 NaN NaN NaN 04/01/2017 18/10/22 2018-12-22
Red Inc 200.0 150.0 140.0 NaN 04/01/2017 17/08/07 2017-10-07