I have a query that looks at a table in my MySQL database and I'm looking to retrieve the data between two datetimes.
At the moment, I get the session and the Table properties assigned just fine:
>>> session
<sqlalchemy.orm.session.Session object at 0x000001EC64FF6EF0>
>>> table
Table('txt_raw1', MetaData(bind=None), Column('datetime', DATETIME(fsp=6), table=<txt_raw1>, nullable=False), and some extra stuff...
I then begin to form the query and so far, so good:
>>> query = session.query(table)
>>> query.filter_by(Name='Jose')
>>> query
<sqlalchemy.orm.query.Query object at 0x000001EC50281A90>
However, when I try to filter by the datetime column, I get an error:
>>> start_date = datetime.strptime('2020-11-10','%Y-%m-%d')
>>> start_date
datetime.datetime(2020, 11, 10, 0, 0)
query.filter_by(datetime > start_date)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: '>' not supported between instances of 'type' and 'datetime.datetime'
Odd thing to me, though, when I checked the first set of data in the query instance, it is of the datetime.datetime format
>>> query[0][0]
datetime.datetime(2019, 11, 16, 1, 43, 54, 192000)
Does anyone have any suggestions to how I can filter by datetime using the type datetime.datetime?