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
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.
Rodrigo Cerda
Rodrigo Cerda 2021-9-12
编辑:Rodrigo Cerda 2021-9-12
I'm on Santiago de Chile, which is currently on GMT-3.
An in fact, Chile switches between GMT-3 and GMT-4 in March every year, bacause of daylight savings.
But the strange thing is that the problematic query requests actually no conversion, since it's converting from GMT to GMT.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Database Toolbox 的更多信息

产品


版本

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by