How to convert a timestamp to date type in Oracle?
In Oracle, you can use the TO_DATE function to convert a timestamp to a date type. The syntax of this function is as follows:
Convert the timestamp expression to a date using the specified format mask and language.
The timestamp_expression is the timestamp expression to be converted, the format_mask is optional and is used to specify the format of the timestamp_expression, and the nls_language is optional and is used to specify the language environment.
Here is an example:
SELECT TO_DATE('2021-01-01 09:30:00', 'YYYY-MM-DD HH24:MI:SS') AS converted_date
FROM dual;
This will return a result set containing the converted date value. In this example, the timestamp_expression is ‘2021-01-01 09:30:00’ and the format_mask is ‘YYYY-MM-DD HH24:MI:SS’, indicating that the format of the timestamp_expression is year, month, day, hour, minute, and second.
Please note that the converted date value will not include the time part, only the date part. If you need to keep the time part, you can use the TO_TIMESTAMP function to convert the timestamp to a timestamp with time zone type.