0

I am trying to read a SQL date in a query within Python and have it run on the first of every month and be filtered for that date. I know how to read in the SQL query in python but I was wondering how I specify the code to change the where (where date = '') to the date I want (ex. 1-1-20 and then 2-1-20 and so on) and also have the query run automatically throughout time.

Muzzamil
  • 2,665
  • 2
  • 8
  • 22
Joe
  • 9
  • 6

1 Answers1

0

In your script in Python you just need to query using the date of run:

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

And if you want to automate the execution, then depends on your SO. In linux you could use a cronjob.

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

Some SO links:

How to get the current time in Python

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

cabesuon
  • 3,992
  • 2
  • 12
  • 21