I have a table t1 with a “ColDate” field. I would like rows whose ColDate is between the start and end of the month. I have a date_py variable, I would like get the month before date_py then take the lines according to the month before
from datetime import datetime
date_ = datetime.today()
date_py = date_aujourdhui.strftime('%Y-%m-%d')
sql_query = f"""
SELECT *
FROM t1
WHERE "ColDate" >= DATE_TRUNC('month', '{date_py }'::date - INTERVAL '1 month')
AND "ColDate" < DATE_TRUNC('month', '{date_py}'::date)
"""
table = pd.read_sql(sql_query, connexion)
Erreur
LINE 4: WHERE "DateMES" >= DATE_TRUNC('month', '2024-06-28'::date - ...
^
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.