this is my code, query Notification.create_time
result = session.query(
Notification.content, cls.is_read,
Notification.create_time).join(
cls, Notification.id == cls.notification).filter(
and_(cls.user == user_id)).order_by(
Notification.create_time.desc()).all()
in other place need to json.dumps query result to frontend, datetime format cann't json.dumps, so I want to do like this:
session.query(Notification.create_time.strftime('%Y-%m-%d %H:%M'))
so, how to change datetime to string in sqlalchemy query?
to_charfor timestamp formatting, which you could call usingsqlalchemy.func. But the (imo) better solution would be to use a JSON serializer that handlesdatetimeobjects.