Search code examples
c#sqlpostgresqltimezonetimezone-offset

PostgreSQL query returning different results in DbEaver and C# (Dapper/ADO.NET) despite same server connection


It's currently 1:15 AM on April 23rd, 2024. My timezone is GMT +7. I have a C# application and a DbEaver application both connecting to the same PostgreSQL server. I execute a very simple query as follows: select current_date.

DbEaver result: '2024-04-23'

C# result (both Dapper and ADO.NET): '2024-04-22'.

I have identified the issue because my query results with the condition datetime > current_date are incorrect.

Please explain to me the cause and how to fix the issue. I greatly appreciate your help


Solution

  • The value of the timezone parameter must be different in the two sessions, so that values of the data type timestamp with time zone are rendered differently.

    Use the SQL statement SET to adjust the parameter to the time zone appropriate for your session:

    SET timezone = 'Europe/Vienna';