I have SQL connection and named db_connection that I run in weekly basis
tran= pd.read_sql('SELECT order_id, p.user_id, p.barcode, title, o.timestamp, amount, p.name, qty FROM transactions t left join orders o on t.order_id = o.id left join products p on t.product_id = p.id where date(o.timestamp)<=\'2017-09-27\' and date(o.timestamp)>=\'2017-09-21\' and p.user_id = \'63165\' ', con=db_connection)
tran2= pd.read_sql('SELECT order_id, p.user_id, p.barcode, title, o.timestamp, amount, p.name, qty FROM transactions t left join orders o on t.order_id = o.id left join products p on t.product_id = p.id where date(o.timestamp)<=\'2017-09-27\' and date(o.timestamp)>=\'2017-09-21\' and p.user_id = \'62345\' ', con=db_connection)
...
tran22= pd.read_sql('SELECT order_id, p.user_id, p.barcode, title, o.timestamp, amount, p.name, qty FROM transactions t left join orders o on t.order_id = o.id left join products p on t.product_id = p.id where date(o.timestamp)<=\'2017-09-27\' and date(o.timestamp)>=\'2017-09-21\' and p.user_id = \'78345\' ', con=db_connection)
For example, I want to change all the date to date(o.timestamp)<=\'2017-10-04\' and date(o.timestamp)>=\'2017-09-28\', but it takes time and is prone to mistakes. Is there any solution to make the date is only called once?