python - 获取时间戳不是今天日期的记录
问题描述
我有如下代码来获取今天的日期:
today = str(date.today()) //2019-01-07
我想从数据库中获取timestamp
列与今天不同的所有记录。功能如下:
def get_vehicle_references():
conn = db_connection()
cur = conn.cursor()
s = "SELECT reference, reference_url FROM vehicles v WHERE (NOT EXISTS (select reference from daily_run_vehicle rv WHERE (handled = %s or (handled = %s and retries >= %s)) and DATE(rv.timestamp) <> %s AND reference = v.reference))"
cur.execute(s, (True, False, 5, today))
return cur.fetchall()
时间戳列采用以下格式:2019-01-07 11:10:18.491368
我想从vehicles
表中timestamp
的列daily_run_vehicle
不是今天的表中获取所有记录。
但是这个查询也给了我今天日期的记录。
任何想法?
更新:
因此我尝试对其进行转换,查询如下:
s = "SELECT reference, reference_url, timestamp FROM vehicles v WHERE (NOT EXISTS (select reference from daily_run_vehicle rv WHERE (handled = %s or (handled = %s and retries >= %s)) AND rv.timestamp::date = %s AND reference = v.reference))"
cur.execute(s, (True, False, 5, today))
但我仍然有同样的问题。
解决方案
推荐阅读
- django - 如何在 django 中将多个值呈现为字符串
- javascript - 计算属性只触发一次
- css - 两边的边距相同,但看起来仍然不居中
- bash - 为什么 bash 认为第 10 行有语法错误?
- react-native - 我无法使用路由器从 NavigationBar 禁用后退按钮
- ruby-on-rails - 我的毁灭?并投票?即使我已授权,方法也无法与 Pundit 一起使用
- python-3.x - 如何重命名Dataframe中重复列中的所有名称
- java - Spring Boot RabbitMQ Receiver JUnit 测试在完成前停止
- python - 将字符串格式的日期时间插入我的数据库导致我出现此错误。有什么解决办法吗?
- php - 在没有作曲家的情况下将 php 从 5.6 迁移到 7.2 时升级第 3 方库