Wrong MySQL query result when accessing through Matlab

6 ビュー (過去 30 日間)
Rodrigo Cerda
Rodrigo Cerda 2021 年 9 月 11 日
編集済み: Rodrigo Cerda 2021 年 9 月 12 日
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 Center および File ExchangeDatabase Toolbox についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by