Borrar filtros
Borrar filtros

Wrong MySQL query result when accessing through Matlab

1 visualización (últimos 30 días)
Rodrigo Cerda
Rodrigo Cerda el 11 de Sept. de 2021
Editada: Rodrigo Cerda el 12 de Sept. de 2021
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 comentarios
Walter Roberson
Walter Roberson el 11 de Sept. de 2021
Odd.
What is your local timezone ? I am wondering if the interface is converting the time returned to local time.
Rodrigo Cerda
Rodrigo Cerda el 12 de Sept. de 2021
Editada: Rodrigo Cerda el 12 de Sept. de 2021
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.

Iniciar sesión para comentar.

Respuestas (0)

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by