Kontext Copilot - An AI-powered assistant for data analytics that runs on your local computer. Learn more
Get started
Spark SQL - Convert String to Timestamp
insights Stats
warning Please login first to view stats information.
Raymond
Spark & PySpark
Apache Spark installation guides, performance tuning tips, general tutorials, etc.
*Spark logo is a registered trademark of Apache Spark.
Similar as Convert String to Date using Spark SQL, you can convert string of timestamp to Spark SQL timestamp data type.
Function to_timestamp
Function to_timestamp(timestamp_str[, fmt]) parses the `timestamp_str` expression with the `fmt` expression to a timestamp data type in Spark.
Example:
spark-sql> select to_timestamp('2021-01-09 17:34:59');
to_timestamp('2021-01-09 17:34:59')
2021-01-09 17:34:59
In the above example, the string is in default format of timestamp, thus there is no need to pass in the format parameter. If it is not in the default format, you need to pass in the format string.
Example:
spark-sql> select to_timestamp('2021010917:34:59','yyyyMMddHH:mm:ss'); to_timestamp('2021010917:34:59', 'yyyyMMddHH:mm:ss') 2021-01-09 17:34:59
All the datetime patterns are list in Datetime patterns.
copyright
This page is subject to Site terms.
comment Comments
No comments yet.