3

Trying to save a date in PostgreSQL using Python, it gives me an UTC+2 for my timezone while it is UTC+1 (dont mind the difference, I just used a Python test to get how the timezone is)

In [8]: datetime.datetime.now(pytz.timezone("Africa/Algiers"))
Out[8]: datetime.datetime(2018, 7, 7, 15, 27, 43, 756977, tzinfo=<DstTzInfo 'Africa/Algiers' CET+1:00:00 STD>)

On PostgreSQL, I get

2018-07-07 14:28:04.144505+02

timezone different

This is like postgresql adds a daylight saving while we dont have it in Algeria ?

NB: I use asyncpg

Abdelouahab
  • 7,331
  • 11
  • 52
  • 82

1 Answers1

2

Based on Raymond Nijland's answer, that worked, here is how (from PGAdmin 4) The reason is that the OS forces its own timezone and dont save the one that Python gave him.

Just run those three commands from SQL prompt :

To get which timezone PG uses,

SHOW timezone ;

To get all the timezones available and how PG names them

SELECT * FROM pg_timezone_names ;

Put the right timezone

ALTER DATABASE yourDataBase SET timezone TO 'Africa/Algiers';

Restart the service

sudo systemctl restart postgresql-10.service 

NB: Even if you use moment.js you need to add .zone(+0100) as mentionned here

Abdelouahab
  • 7,331
  • 11
  • 52
  • 82