
The current timestamp has been successfully converted into the current time.

In the below snippet, the TO_CHAR() function is utilized to format the current timestamp into the current time: SELECT TO_CHAR(CURRENT_TIMESTAMP:: TIME, 'HH:MM:SS') The current timestamp has been successfully formatted into the given format.Įxample 5: Formatting Current Timestamp to Current Time in Postgres Use the TO_CHAR() function with the “::” operator followed by the “DATE” data type to format a given timestamp to a date: SELECT TO_CHAR(CURRENT_TIMESTAMP:: DATE, 'MON DD, YYYY') The current timestamp has been successfully formatted into the specified format.Įxample 4: Formatting Current Timestamp to a Date in Postgres In the following snippet, the current timestamp is formatted into the “DAY, DD MONTH YYYY HH:MM:SS” format: SELECT to_char(CURRENT_TIMESTAMP, 'DAY, DD MONTH YYYY HH:MM:SS') The current timestamp has been successfully converted to the specified format.Įxample 3: Formatting Current Timestamp into 'DAY, DD MONTH YYYY HH:MM:SS' Format To format the current timestamp, specify the CURRENT_TIMESTAMP and a particular format to the TO_CHAR() function: SELECT TO_CHAR(CURRENT_TIMESTAMP, 'YYYY/MM/DD HH:MI:SS') The given timestamp has been successfully formatted to a specific format.Įxample 2: Formatting Current Timestamp in Postgres
Format timestamp update postgresql how to#
The following example explains how to format a timestamp in Postgres via the TO_CHAR() function: SELECT TO_CHAR(TIMESTAMP ' 5:55:55', 'YYYY/MM/DD HH:MI:SS') Visit the official Postgres documentation to see the valid formats for the TO_CHAR() function.Įxample 1: Formatting a Timestamp in Postgres The return type of the stated function is “TEXT”. To format a timestamp, specify a timestamp and a valid format as arguments to the TO_CHAR() function: TO_CHAR(TIMESTAMP, format) This post demonstrates how to utilize the TO_CHAR() function to format a timestamp in Postgres. The TO_CHAR() is one of the data type formatting functions that assist us in converting/formatting the data from one type to another. The timestamp data type is more readable.PostgreSQL supports various built-in functions to deal with the timestamp values efficiently, such as CURRENT_TIMESTAMP, TO_TIMESTAMP(), DATE_PART(), etc. In our example, the text date and time ' 7/15:23:45'was converted to the timestamp value 15:23:45+02. The function TO_TIMESTAMP() returns a timestamptz value with time zone information. Notice that the input format is a string. You can find a complete list of datetime pattern elements in the PostgreSQL documentation. Note that we use slashes (/) as date part delimiters and colons (:) as time part delimiters.

ss represents a 2-digit second (from 00 to 59).MI represents a 2-digit minute (from 00 to 59).

