Teradata Package for Python Function Reference | 20.00 - to_timestamp - 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.to_timestamp = to_timestamp(self, format=None, type_=<class 'teradatasqlalchemy.types.TIMESTAMP'>, timezone=None)
- DESCRIPTION:
Converts string or integer to a TIMESTAMP data type or TIMESTAMP WITH
TIME ZONE data type.
Note:
* POSIX epoch conversion is implicit in the "to_timestamp" when column
is integer type. POSIX epoch is the number of seconds that have elapsed
since midnight Coordinated Universal Time (UTC) of January 1, 1970.
PARAMETERS:
format:
Specifies the format of string column.
Argument is not required when column is integer type, Otherwise Required.
For valid 'format' values, see documentation on
"to_date" or "help(df.col_name.to_date)".
Type: ColumnExpression or str
type_:
Optional Argument.
Specifies a TIMESTAMP type or an object of a
TIMESTAMP type that the column needs to be cast to.
Default value: TIMESTAMP
Permitted Values: TIMESTAMP data type
Types: teradatasqlalchemy type or object of teradatasqlalchemy type
timezone:
Optional Argument.
Specifies the timezone string.
For valid timezone strings, user should check Vantage documentation.
Type: ColumnExpression or str.
RETURNS:
ColumnExpression
EXAMPLES:
# Load the data to run the example.
>>> load_example_data("teradataml", "timestamp_data")
# Create a DataFrame on 'timestamp_data' table.
>>> df = DataFrame("timestamp_data")
>>> df
id timestamp_col timestamp_col1 format_col timezone_col
2 2015-01-08 00:00:12.2+10:00 45678910234 YYYY-MM-DD HH24:MI:SS.FF6 TZH:TZM GMT+10
1 2015-01-08 13:00 878986 YYYY-MM-DD HH24:MI America Pacific
0 2015-01-08 00:00:12.2 123456 YYYY-MM-DD HH24:MI:SS.FF6 GMT
>>> df.tdtypes
id INTEGER()
timestamp_col VARCHAR(length=30, charset='LATIN')
timestamp_col1 BIGINT()
format_col VARCHAR(length=30, charset='LATIN')
timezone_col VARCHAR(length=30, charset='LATIN')
# Example 1: Convert Epoch seconds to timestamp.
>>> df.select(['id','timestamp_col1']).assign(col = df.timestamp_col1.to_timestamp())
id timestamp_col1 col
2 45678910234 3417-07-05 02:10:34.000000
1 878986 1970-01-11 04:09:46.000000
0 123456 1970-01-02 10:17:36.000000
# Example 2: Convert timestamp string to timestamp with timezone in
# format mentioned in column "format_col".
>>> df.select(['id', 'timestamp_col', 'format_col']).assign(col = df.timestamp_col.to_timestamp(df.format_col, TIMESTAMP(timezone=True)))
id timestamp_col format_col col
2 2015-01-08 00:00:12.2+10:00 YYYY-MM-DD HH24:MI:SS.FF6 TZH:TZM 2015-01-08 00:00:12.200000+10:00
1 2015-01-08 13:00 YYYY-MM-DD HH24:MI 2015-01-08 13:00:00.000000+00:00
0 2015-01-08 00:00:12.2 YYYY-MM-DD HH24:MI:SS.FF6 2015-01-08 00:00:12.200000+00:00
# Example 3: Convert Epoch seconds to timestamp with timezone in 'GMT+2' location.
>>> df.select(['id', 'timestamp_col1', 'format_col']).assign(col = df.timestamp_col1.to_timestamp(df.format_col, TIMESTAMP(timezone=True), 'GMT+2'))
id timestamp_col1 format_col col
2 45678910234 YYYY-MM-DD HH24:MI:SS.FF6 TZH:TZM 3417-07-05 04:10:34.000000+02:00
1 878986 YYYY-MM-DD HH24:MI 1970-01-11 06:09:46.000000+02:00
0 123456 YYYY-MM-DD HH24:MI:SS.FF6 1970-01-02 12:17:36.000000+02:00