社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

Darren Christopher

Darren Christopher 最近创建的主题
Darren Christopher 最近回复了
5 年前
回复了 Darren Christopher 创建的主题 » 如何使用python在sql select语句中插入今天的日期?

你用的是什么数据库引擎?你需要转换python datetime 对象转换为数据库接受格式的字符串。

# In case YYYY-MM-DD
today_str = str(today)

stmt = f"""select agent_email 
           from customer_interaction_fact 
           where to_date(DT) >= datetime({today}, "YYYY-MM-DD") 
           order by CONVERSATION_CREATED_TIME DESC"""

另一种解决方案是,假设客户机(程序)与数据库引擎位于同一时区,则可以使用数据库引擎 datetime.now 功能。在 SQLite 例如 datetime('now')