Wrong MySQL query result when accessing through Matlab

조회 수: 3 (최근 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 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