【问题标题】:how to change SQL date in python, auto run如何在python中更改SQL日期,自动运行
【发布时间】:2020-05-02 14:14:21
【问题描述】:

我正在尝试在 Python 中的查询中读取 SQL 日期,并让它在每个月的第一天运行并针对该日期进行过滤。我知道如何在 python 中读取 SQL 查询,但我想知道如何指定代码以将 where (where date = '') 更改为我想要的日期(例如 1-1-20 然后 2-1-20 等等),还有让查询始终自动运行。

【问题讨论】:

    标签: python sql filter automation anaconda


    【解决方案1】:

    在您的 Python 脚本中,您只需要使用运行日期进行查询:

    today = datetime.today()
    query_date = '{}-{}-{}'.format(today.month, 1, today.year)
    

    如果您想自动执行,则取决于您的 SO。在 linux 中,您可以使用 cronjob。

    0 0 1 * * /path/to/script.py

    一些 SO 链接:

    How to get the current time in Python

    how to create a cron job that runs on the first day of month [duplicate]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-03-27
      • 2022-08-05
      • 1970-01-01
      • 2013-09-10
      • 2016-06-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多