Arjun Sethumadhavan
Arjun Sethumadhavan

Reputation: 11

How to get date time with time zone as string from sqlalchemy

I am using postgresql db with sqlalchemy

When I use the query select now() directly I get a result that can be converted into string, but I can't produce this output using sqlalchemy.

Already I have used the following module which is not giving me the result I needed from sqlalchemy: import func

Upvotes: 1

Views: 706

Answers (1)

davidism
davidism

Reputation: 127410

The func module is a proxy that creates functions. So func.now() will produce the column you want.

now = session.query(func.now()).scalar()

This returns a Python datetime object.

Upvotes: 3

Related Questions