Sqlalchemy使用func.now()将来将一个字段设置为1小时

发布于 2025-02-09 07:01:44 字数 304 浏览 1 评论 0原文

我想将未来的时间戳存储在我的数据库中,但理想情况下使用SQLalchemy的func.now()函数和timedelta。这可能吗?类似:

new_obj = MyTable(event_time=(func.now() + OFFSET))

我可以使用dateTime.utcnow()来做到这一点,但这不是100%理想。似乎应该有可能使用偏移来进行func.now(),并且避免解释为什么我们的事件和创建的时间戳略微不匹配,即使这是次秒差异。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

飞烟轻若梦 2025-02-16 07:01:44

以下操作:

    timestamp = datetime.now() + timedelta(hours=1)

或:

    timestamp = func.now() + timedelta(hours=1)

您可以在此处找到 timedelta上的文档: htttps:// https:// docs.python.org/3/library/datetime.html

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文