postgresqlHow do I format a date in PostgreSQL?
Formatting a date in PostgreSQL is a fairly straightforward process. The following example code block demonstrates how to format a date in PostgreSQL:
SELECT to_char(current_date, 'DD-Mon-YYYY') AS "Formatted Date";
The output of this code is:
Formatted Date
--------------
18-Aug-2020
This code formats the current date in the format of Day-Month-Year. The code is broken down into a few parts:
SELECT: This is the command used to retrieve data from the database.to_char(current_date, 'DD-Mon-YYYY'): This is the function used to format the date.current_dateis the date to be formatted and'DD-Mon-YYYY'is the format in which the date should be displayed.AS "Formatted Date": This is the alias given to the result of the query.
For more information on formatting dates in PostgreSQL, please refer to the following links:
More of Postgresql
- How can I troubleshoot zero damaged pages in PostgreSQL?
- How can I use PostgreSQL with YAML?
- How can I monitor PostgreSQL performance using Zabbix?
- How do I set up PostgreSQL Kerberos authentication?
- How can I use PostgreSQL on the Yandex Cloud platform?
- How do I use PostgreSQL's XMIN and XMAX features?
- How do I use PostgreSQL's XMLTABLE to parse XML data?
- How can I use PostgreSQL XOR to compare two values?
- How do I use PostgreSQL with Qt?
- How do I use PostgreSQL's ON CONFLICT DO NOTHING clause?
See more codes...