TO_TIMESTAMP
Description
The TO_TIMESTAMP function is used to convert different types of date-time expressions (expr) into a timestamp type. If the fmt parameter is provided, the function will parse according to the specified format; if fmt is not provided, it will convert according to the default format. If the date-time format in expr is incorrect, the function will return null.
Parameter Description
- expr (string): The string expression to be converted.
- fmt (string, optional): Specifies the format of the date-time in the string expression.
Return Result
The converted timestamp.
Usage Example
-
Convert a string to a timestamp (without specifying the fmt parameter):
-
Convert the string to a timestamp according to the specified format:
-
Convert different types of date-time strings to timestamps:
-
Convert illegal date-time strings:
Please note that the TO_TIMESTAMP function will return null when processing illegal date-time strings. Therefore, when using this function, ensure that the input string format is correct. Additionally, you can flexibly handle date-time strings in different formats through the fmt parameter.