In postgres I have a table with date column. Now postgres allows me to write date in Y-m-d format. But I need date in d/m/Y format. How to change it?
When I do:
show datestyle;
I get:
"ISO, DMY"
And input date in table in this format 13/02/2009
But when I close and open table again I see this 2009-02-13
. JDBC gives me date in this format too. What am I doing wrong?
You can change the format in the postgresql. conf file. The date/time styles can be selected by the user using the SET datestyle command, the DateStyle parameter in the postgresql. conf configuration file, or the PGDATESTYLE environment variable on the server or client.
PostgreSQL uses the yyyy-mm-dd format for storing and inserting date values. If you create a table that has a DATE column and you want to use the current date as the default value for the column, you can use the CURRENT_DATE after the DEFAULT keyword.
First, specify the name of the table to which the column you want to change after the ALTER TABLE keywords. Second, specify the name of the column that you want to change the data type after the ALTER COLUMN clause. Third, supply the new data type for the column after the TYPE keyword.
you also can use the command
set datestyle to [your new datestyle];
in the console of postgreSQL.
yyyy-mm-dd is the recommended format for date field, its the ISO 8601 format.
You can change the format in the postgresql.conf file.
The document states
The date/time styles can be selected by the user using the SET datestyle command, the DateStyle parameter in the postgresql.conf configuration file, or the PGDATESTYLE environment variable on the server or client. The formatting function to_char is also available as a more flexible way to format date/time output.
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With