Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. GEt MySQL Datetime into QDate and show Date
Forum Update on Monday, May 27th 2025

GEt MySQL Datetime into QDate and show Date

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 979 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Philipp DE
    wrote on last edited by
    #1

    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?

    Pablo J. RoginaP 1 Reply Last reply
    0
    • P Philipp DE

      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?

      Pablo J. RoginaP Offline
      Pablo J. RoginaP Offline
      Pablo J. Rogina
      wrote on last edited by
      #2

      @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

      Upvote the answer(s) that helped you solve the issue
      Use "Topic Tools" button to mark your post as Solved
      Add screenshots via postimage.org
      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      3
      • P Offline
        P Offline
        Philipp DE
        wrote on last edited by
        #3

        Thank you so much!

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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved