Wrong MySQL query result when accessing through Matlab
5 次查看(过去 30 天)
显示 更早的评论
I'm accessing MySQL through Matlab, using the following code:
dbName = 'dbName' ;
DB.(dbName) = database(dbName,'user','password');
openDateTimeStr = '2006-03-17 00:00:00';
timeZoneOpen = 'GMT';
queryStr = ['SELECT CONVERT_TZ(''' openDateTimeStr ''', ''' timeZoneOpen ''', ''GMT'')'];
setdbprefs('datareturnformat', 'cellarray')
curs = exec(DB.(dbName), queryStr);
curs = fetch(curs);
result = curs.Data;
close(curs);
and I get the following result, which is 1 hour earlier than what it should be:
result = 1×1 cell array
{'2006-03-16 23:00:00.0'}
But when I type the exact same query directly into MySQL Workbench, I get the correct result:
SELECT CONVERT_TZ('2006-03-17 00:00:00', 'GMT', 'GMT')
-> '2006-03-17 00:00:00'
On the other hand, if I do the same request but for an earlier date (eg: 2006-01-06) both queries (Matlab and MySQL Workbench) return the same (correct) result.
Hence it seems to me like a sort of daylight savings issue that's generating a problem when I access MySQL through Matlab, but not when I access MySQL through it's Workbench.
Any ideas on what might be going on? and how to fix this?
2 个评论
Walter Roberson
2021-9-11
Odd.
What is your local timezone ? I am wondering if the interface is converting the time returned to local time.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Database Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!