Why datetime doesn't give the expected result in Python?

40 views Asked by At

I have these datetime :

    start = datetime(2023, 12, 10, 11, 0, 0, tzinfo=pytz.timezone('Europe/Paris'))
    stop = datetime(2023, 12, 10, 11, 1, 0, tzinfo=pytz.timezone('Europe/Paris'))

Using "offset" instead of "time zone", these should correspond to :

'2023-12-10T11:00:00+01:00'::timestamptz for start and

'2023-12-10T11:01:00+01:00'::timestamptzfor stop.

But when I try to use these datetimes in a PgSQL query (using psycopg2 driver), this is the transformation I get :

                select = """
                    SELECT *
                    FROM my_table
                    WHERE code = %s
                    AND time >= %s
                    AND time < %s
                    ORDER BY time ASC
                """
                cursor.execute(select, (code, start, stop))
                print (cursor.query)

The printed query is :

SELECT *
FROM my_table
WHERE code = 'CODE1'
AND time >= '2023-12-10T11:00:00+00:09'::timestamptz
AND time < '2023-12-10T11:01:00+00:09'::timestamptz
ORDER BY time ASC

Where does this "+00:09" come from ? why is it not "+01:00" ?

0

There are 0 answers