Reputation: 6275
I want to store a future timestamp in my DB but ideally using SQLAlchemy's func.now()
function and a timedelta. Is this possible? Something like:
new_obj = MyTable(event_time=(func.now() + OFFSET))
I can do this using datetime.utcnow()
but it's not 100% ideal. It seems like it should be possible to do func.now()
with an offset, and it would avoid explaining why our event and created timestamps are slightly mismatched, even if it is a sub-second difference.
Upvotes: 1
Views: 1519
Reputation: 58
you can do the following:
timestamp = datetime.now() + timedelta(hours=1)
or:
timestamp = func.now() + timedelta(hours=1)
Documentation on timedelta can be found here: https://docs.python.org/3/library/datetime.html
Upvotes: 1