Date Format (pgsql)

1.4k views Asked by At

I have an old import script which uses SQLAlchemy (0.8.3) and psycopg2 (2.5.1). Now I am migrating it to a newer server with SQLAlchemy (1.0.5) and psycopg2 (2.5.4).

My date format is mostly "dd.MM.yyyy" and I get this error

DataError: (psycopg2.DataError) date/time field value out of range: "02.12.2014"
LINE 3: ...sv.matnr_id = '216812' AND pbis.ksv.zeitstempel = '02.12.201...

In the old version (if the date format was different) I used

 Column('field', Date(storage_format="%(day)02d.%(month)02d.%(year)04d"), primary_key=True),

but this does not work in the newest version.

How can I tell Date my format?

Thanks

Edit: Python Version 2.7.9

1

There are 1 answers

0
Beig On BEST ANSWER

As explained here https://bitbucket.org/zzzeek/sqlalchemy/issue/3446/regression-date-takes-no-parameters the parameter was ignored.

Using datetime.strptime(date, '%d.%m.%Y') is sufficient.