postgresqlHow can I convert a PostgreSQL timestamp to a date?
To convert a PostgreSQL timestamp to a date, you can use the to_date
function. This function takes a timestamp as an argument and returns a date. For example:
SELECT to_date('2020-04-30 12:34:56', 'YYYY-MM-DD HH24:MI:SS')
Output example
2020-04-30
The code above contains the following parts:
SELECT
: This is a keyword used to select a value from a table.to_date
: This is the function used to convert a timestamp to a date.'2020-04-30 12:34:56'
: This is the timestamp argument passed to theto_date
function.'YYYY-MM-DD HH24:MI:SS'
: This is the format of the timestamp argument.
For more information, please refer to the PostgreSQL Documentation.
More of Postgresql
- How do I use PostgreSQL's XMLTABLE to parse XML data?
- How do I decide whether to use PostgreSQL VARCHAR or TEXT data types?
- How do I use the PostgreSQL string_agg function?
- How can I compare PostgreSQL and MSSQL for software development?
- How do I use the PostgreSQL NVL function?
- How can I use PostgreSQL and ZFS snapshots together?
- How can I troubleshoot zero damaged pages in PostgreSQL?
- How can I use PostgreSQL with YAML?
- How can I retrieve data from PostgreSQL for yesterday's date?
- How do I use PostgreSQL's XMIN and XMAX features?
See more codes...