Skip to content
Advertisement

How to insert today’s date in SQL select statement using python?

I’m trying to send today variable into SQL but it is not working.

import datetime from date

today = date.today()


stmt = "select agent_email from customer_interaction_fact where to_date(DT) >= + today + ORDER BY CONVERSATION_CREATED_TIME DESC"

Advertisement

Answer

You don’t have to compute today’s date in Python. Just use the PostgreSQL function CURRENT_DATE:

stmt = "SELECT ... WHERE TO_DATE(DT) >= CURRENT_DATE ..."
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement