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 I use PostgreSQL with YAML?
- How can I use PostgreSQL and ZFS snapshots together?
- How do I use PostgreSQL's XMIN and XMAX features?
- How can I use PostgreSQL's "zero if null" feature?
- How can I use PostgreSQL with Zabbix?
- How can I use PostgreSQL XOR to compare two values?
- How do I use PostgreSQL ZonedDateTime to store date and time information?
- How can I extract the year from a date in PostgreSQL?
- How do I convert a string to lowercase in PostgreSQL?
See more codes...