How to configure Postgres to accept date in PT-BR format?

Asked

Viewed 2,505 times

3

Situation

Let’s say I have one form in which the user fills a field date, DD-MM-YYYY.

Question

How can I do the postgres accept this format normally?

  • No need to do to_timestamp('14/06/2016', 'DD-MM-YYYY')

Addendum

  • The SELECT was YYYY-MM-DD.
  • The INSERT accept YYYY-MM-DD or DD-MM-YYYY.
  • Yes it is possible, :D even had an answer .... I just can’t find it

  • @rray hehe, was intentional to help, because I saw that the site did not have. : D

  • I used this, only I always set this setting in the session.

  • @rray SET datestyle TO "ISO, DMY";?

  • That, even, hehe you mode not always mess shape Globa on the server there already saw. I found :)

1 answer

6


Researching a little I found this answer.

The steps are simple :

  1. Check your current datestyle "ISO, DMY" or "IOS, MDY".
  2. Now Depending on what you want in the postgres MDY or DMY

    ALTER DATABASE "my_database_name" SET datestyle TO "ISO, DMY";

    or

    ALTER DATABASE "my_database_name" SET datestyle TO "ISO, MDY";

  3. After this it will be necessary to restart the server

    sudo service postgresql Restart

    Or

    sudo /etc/init. d/postgresql Restart

  4. Test the configuration

    Query: SELECT '12/20/2016':date Output: "2016-12-20"

    Or

    Query: SELECT '12/19/2016':date Output: "2016-12-19"

In this case we use, ALTER DATABASE "my_database_name" SET datestyle TO "ISO, DMY";.

  • I make a caveat, once it was necessary to change this also in the postgres configuration file

Browser other questions tagged

You are not signed in. Login or sign up in order to post.