Important: Please read the Qt Code of Conduct -

GEt MySQL Datetime into QDate and show Date

  • Hi,

    in my MySQL database I have a date_added column of type DATETIME. I like to store that time into qDate and than later show that date in my local date format.

    When I do the MySQL output with qDebug like

    qDebug() << "Date: " << query.value("date_added").toString();

    I get the output:
    Date: "2020-08-14T13:56:20.000"

    This is what I try:

    QDate date = QDate::fromString(query.value("date_added").toString(), "yyyy-MM-dd hh:mm:ss.zzz");
    qDebug() << "Date: " << date.toString("dd.MM.yyyy");

    The output is empty. I think the problem is the T inside the date. When I look into phpmyadmin it only shows "2020-08-14 13:56:20".

    Does anybody has an idea how I get the qDate filled correctly?

  • @Philipp-DE said in GEt MySQL Datetime into QDate and show Date:

    QDate date = QDate::fromString(

    It looks like you're looking for QDateTime::fromString(), using Qt::ISODate as the format

  • Thank you so much!

    I tried to do manuell, but i did not know that there is a Qt::ISODate. This works fine!

Log in to reply