0

I have the following:

class Atom(Base):
    __tablename__ = 'atom'

    id                = Column( Integer, primary_key=True)
    date              = Column( Date, nullable=False,  doc="date on which delivery occurred" )`

I look at the sql sent and I see the following for date 'date': datetime.datetime(2016, 3, 1, 0, 0, tzinfo=tzutc())

so when I pass 2016-03-01 and look in db I see 2016-02-29

How can I stop sqlachemy from adding the tzinfo for a Date type?

univerio
  • 19,548
  • 3
  • 66
  • 68
CrabbyPete
  • 505
  • 9
  • 18

1 Answers1

0

The solution would be:

date = Column(DateTime(timezone=False),
              nullable=False,
              doc="date on which delivery occurred"
       )

According to the SQLAlchemy Changelog you can switch the time zone in this way:

added “timezone=True” flag to DateTime and Time types. postgres so far will convert this to “TIME[STAMP] (WITH|WITHOUT) TIME ZONE”, so that control over timezone presence is more controllable (psycopg2 returns datetimes with tzinfo’s if available, which can create confusion against datetimes that don’t).

Another option is to set the specific timezone, explained here.

Community
  • 1
  • 1
Joost Döbken
  • 3,450
  • 2
  • 35
  • 79