[英]Rare Incident when setting dates range in where of a query of MySql?
I'm programming Classic ASP against a MySql Database connecting with ADODB and MySQL ODBC 5.3 ANSI Driver, but I have some problems when setting the date in the where of a simple MySql query, when my query is: 我正在编写针对连接ADODB和MySQL ODBC 5.3 ANSI驱动程序的MySql数据库的经典ASP,但是当我在一个简单的MySql查询的位置设置日期时遇到一些问题,当我的查询是:
Select * from cdr where date(calldate)='20170901'
The query retrieve data in the asp page, thats ok, but when the query is 查询检索asp页面中的数据,没关系,但是当查询是
Select * from cdr where date(calldate) between '20170801' and '20170828'
When I print the query and then I copy from html and paste into Mysql Workbench, then it retrieve data, but when in the asp page itself does not retrieve a any data. 当我打印查询然后我从html复制并粘贴到Mysql Workbench,然后它检索数据,但在asp页面本身不检索任何数据。
Any Ideas? 有任何想法吗? I think maybe is something with de ODBC Driver. 我想也许是de ODBC Driver的东西。
If you want use a not mysql default date format you must convert properly 如果要使用非mysql默认日期格式,则必须正确转换
Select * from cdr where date(calldate)=str_to_date('20170901','%Y%m%d')
otherwise use the mysql default format 否则使用mysql默认格式
Select * from cdr where date(calldate)='2017-09-01'
I would not trust this format: '20170801'
我不相信这种格式: '20170801'
Since calldate
is DATETIME
, this would be faster: 由于calldate
是DATETIME
,因此速度会更快:
WHERE calldate >= '2017-08-01'
AND calldate < '2017-08-01' + INTERVAL 28 DAY`.
It would require INDEX(calldate)
它需要INDEX(calldate)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.