我正在编程经典的ASP,以与AdoDB和MySQL ODBC 5.3 ANSI驱动程序连接的MySQL数据库,但是当在简单的mysql查询中设置日期时,我有一些问题我的查询是:
Select * from cdr where date(calldate)='20170901'
查询在ASP页面中检索数据,没关系,但是当查询为
时Select * from cdr where date(calldate) between '20170801' and '20170828'
当我打印查询时,然后从html复制并粘贴到mysql workbench中,然后检索数据,但是当在ASP页面中未检索任何数据时。
有什么想法吗?我认为也许是De ODBC驱动程序。
如果要使用不是mysql默认日期格式,则必须正确转换
Select * from cdr where date(calldate)=str_to_date('20170901','%Y%m%d')
否则使用MySQL默认格式
Select * from cdr where date(calldate)='2017-09-01'
我不会相信这种格式: '20170801'
由于 calldate
是 DATETIME
,这会更快:
WHERE calldate >= '2017-08-01'
AND calldate < '2017-08-01' + INTERVAL 28 DAY`.
它需要INDEX(calldate)