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:
Select * from cdr where date(calldate)='20170901'
The query retrieve data in the asp page, thats ok, but when the query is
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.
Any Ideas? I think maybe is something with de ODBC Driver.
MySQL NOW() Function The NOW() function returns the current date and time. Note: The date and time is returned as "YYYY-MM-DD HH-MM-SS" (string) or as YYYYMMDDHHMMSS.
MySQL retrieves and displays DATE values in ' YYYY-MM-DD ' format. The supported range is '1000-01-01' to '9999-12-31' .
The current date format is 'YYYY-mm-dd'. To change current date format, you can use date_format().
If you want use a not mysql default date format you must convert properly
Select * from cdr where date(calldate)=str_to_date('20170901','%Y%m%d')
otherwise use the mysql default format
Select * from cdr where date(calldate)='2017-09-01'
I would not trust this format: '20170801'
Since calldate
is DATETIME
, this would be faster:
WHERE calldate >= '2017-08-01'
AND calldate < '2017-08-01' + INTERVAL 28 DAY`.
It would require INDEX(calldate)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With