Save date in Brazilian format in Postgresql

Asked

Viewed 952 times

3

I have a Postgresql database on the Windows Azure server that is set to the Brazilian standard.

If I do an SQL and run directly in Pgadminiii there from the server and run, the date is saved in Brazilian format.

But if I send my C# (local or Azure) code to execute SQL, the date is saved in American format. I already debug my code and saw that the date is Brazilian, it mounts the SQL string with the Brazilian date, but when it runs it is saved as American.

Both the code and my direct access to Postgre’s Pgadminiii are with the same user. Why does this happen? Why does manually running become Brazilian and when the code runs becomes American? Can anyone help, please? They’ve had similar problems?

  • 2

    Which culture is configured in your application?!

  • 1

    Could you post the respective snippet of your C#code, please?

  • I had a similar problem and I solved that tag <globalization Culture="en-BR" uiCulture="en-BR" /> in webconfig inside the tag <system.web> or then configure in globlal.asax.

3 answers

3

I know two ways to force culture on Asp.net

First:

In the web.config within the tag <system.web> you add the following tag

 <globalization culture="pt-BR" uiCulture="pt-BR" />

Second

Within the global.asax in the method Application_BeginRequest, you add two lines

Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("pt-BR");
Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("pt-BR");

So each request will have its own culture.

The first line will set the date format.

The second line specifies which location resource to load.

  • I will test this second option. Thank you.

1

  • I actually needed to change the storage format myself. Even though I treated him in my code after with the correct culture, he was saving reversed in the field at the bank. Solved as I said there in the reply. May not be the most correct but for now, solved my problem. Thank you very much for the help.

  • @user3207729 This is point. There is no "storage format". The database saves data type DATE and ready - usually an integer representing the amount of seconds since 01/01/1900 or something like that. And that goes for floating numbers too, the comic saves values, whether decimals are separated by a comma or a period. What will define this format that concerns you is the showing off, vc can display dates in the format you like: YYYYMMDD, DD/MM/YYYY, MM/DD/YYYY, etc.

  • @Thiago Lunardi: What you described above was not the "storage format"?

  • @Anonimo I started by saying: "There is no "storage format"".

  • @Thiago Lunardi: If what is stored in the bank is a value representing a date, in the case of the date type, or an instant of time, in the case of the timestamp type, then this value is stored according to a format intelligible by the DBMS, so there is a storage format, and what is stored can be displayed in the most varied display formats for date or time instant.

0

I tested the solutions but was not yet successful. I was able to solve by passing the date as string parameter in my SQL using the format yyyy-MM-dd. So the postgre saves correctly in the timestamp field.

Thank you all for the tip. Serves learning. Thanks!

  • I repeat that you are confusing the storage format of a date field, or timestamp, which is internal and you can not change with the display format that you can control at your pleasure.

Browser other questions tagged

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