Incorrect date/time pulled in Matlab MySQL query

2 vues (au cours des 30 derniers jours)
Allan Brett
Allan Brett le 5 Fév 2021
Commenté : Allan Brett le 8 Fév 2021
I have a database on a remote server that is storing a mysql timestamp. This value is created from an epoch timestamp. When I run a query directly on the server through the command line it returns these fields as follows (mysql timestamp on the left / epoch timestamp on the right):
2020-09-07 17:02:14 | 1599498134 |
Note this result is from a simple query (select * from table where id = value)
When I run the same query through Matlab it returns:
'2020-09-07 11:02:14.0' | 1599498134 |
You will notice the hours have been shifted and there is now a '.0' added at the end. It seems to be auto-adjusting to local time for some reason (the epoch time is in GMT). The query is run through the 'DATA = select(connection, statement);' syntax. Any assistance on how to resolve this is appreciated.
I am using Matlab R2016b

Réponse acceptée

Manas Meena
Manas Meena le 8 Fév 2021
You can either configure the MySQL server to the required timezone.
Also you can try out something like the following command to set driver parameters for timezone in MATLAB
>> conn = database('',<username>,<password>,'com.mysql.cj.jdbc.Driver','jdbc:mysql://servername:portnumber/databasename?serverTimezone=UTC&')
  1 commentaire
Allan Brett
Allan Brett le 8 Fév 2021
Thank you. The issue was a mismatch between the server timezone and how I had configured the connection.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by