How to get current date and time from DB using SQLAlchemy How to get current date and time from DB using SQLAlchemy database database

How to get current date and time from DB using SQLAlchemy


I foud the solution: these functions cannot be used in the way I used (print...), but need to be called inside of the code that interacts with the database. For instance:

print select([my_table, func.current_date()]).execute()

or assigned to a field in an insert operation.Accidentally I discovered that exists at least a couple of parameters for these functions:

  • type_ that indicates the type of the value to return, I guess
  • bind that indicates a binding to an SQLAlchemy engine

Two examples of use:

func.current_date(type_=types.Date, bind=engine1)func.current_timestamp(type_=types.Time, bind=engine2)

Anyway my tests seems to say these parameters are not so important.