Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-135135

QMySqlDriver QDateTime is not consistant between read/write

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.8.2
    • SQL Support
    • None

    Description

      When writing a QDateTime in a DATETIME sql field (in a MySQL datatbase) QMYSQLDriver::formatValue returns a string like that

      r = u'\'' +
                              dt.date().toString(Qt::ISODate) +
                              u'T' +
                              dt.time().toString(Qt::ISODate) +
                              u'\'';

      and QMYSQLResult::data reads it like that

      return QDateTime(date, time, QTimeZone::UTC); 

      Assuming it is always stored in UTC.

      However, if a localTime is passed to the formatValue method (for instance QDateTime(2025-03-25 11:14:25.000 CET Qt::LocalTime)) it is stored in this format "2025-03-25T11:14:25". But when it is retrived with a SELECT, it is returned as QDateTime(2025-03-25 11:14:25.000 UTC Qt::UTC)

      Edit: I know that in the docs https://doc.qt.io/qt-6/sql-driver.html#timestamp-support it says it is normal, but since MySQL does not store any timezone information, the retrieved data should not be assumed to be UTC 

       

      Attachments

        For Gerrit Dashboard: QTBUG-135135
        # Subject Branch Project Status CR V

        Activity

          People

            chehrlic Christian Ehrlicher
            romain.donze Romain Donzé
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes