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_date
is 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 Zalando use PostgreSQL to improve its software development?
- How do I install and configure PostgreSQL on a Windows machine?
- How can I use PostgreSQL and ZFS snapshots together?
- How can I set a PostgreSQL interval to zero?
- How can I use PostgreSQL XML functions to manipulate XML data?
- How can I convert XML data to a PostgreSQL table?
- How can I use PostgreSQL and Node.js together to develop a software application?
- How do I use the PostgreSQL hash function?
- How can I use PostgreSQL's "zero if null" feature?
See more codes...