Save date in Brazilian format in Postgresql

3

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

If I do a SQL and execute directly on PgAdminIII from the server and execute, the date is saved in the Brazilian format.

But if I have my C # code (local or Azure) run SQL, the date is saved in the American format. I have done a debug in my code and I saw that the date is Brazilian, it mounts the SQL string with the Brazilian date, but when it executes it it is saved as American.

Both the code and my direct access to PgAdminIII from Postgre are with the same user. Why does it happen? Why is running manually Brazilian and when the code executes is American? Can someone help, please? Have you ever had a similar problem?

    
asked by anonymous 10.05.2017 / 02:46

3 answers

3

I know two ways to force culture in Asp.net

  

First:

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

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

Second

Within the global.asax in the Application_BeginRequest method, 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 localization feature to load.

    
10.05.2017 / 14:40
1

You are confusing storage format with date or timestamp field display format.

You can not change the storage format of these data types, but you can change the display format.

See item 8.5.2. (Date / Time Output) of the manual:

link

Using the to_char function gives you full control over how to display the date. link

    
10.05.2017 / 15:57
0

I tested the solutions but still did not succeed. I was able to resolve by passing the date as a string parameter in my SQL using the yyyy-MM-dd format. So postgre saves correctly in the timestamp field.

Thanks to everyone for the tip. It serves as learning. Thanks!

    
11.05.2017 / 04:40