DB2 Timestamp to String: TO_CHAR Guide

In DB2, you can use the TO_CHAR function to convert a timestamp to a string. Here is an example:

SELECT TO_CHAR(current_timestamp, 'YYYY-MM-DD HH24:MI:SS') AS formatted_timestamp
FROM dual;

In the example above, current_timestamp represents the current timestamp, ‘YYYY-MM-DD HH24:MI:SS’ is the string format you want to convert the timestamp to. You can customize the formatting string to suit your needs.

bannerAds