Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Undefined behaviour of QDate when converted to string

    General and Desktop
    qdate c++ qt
    2
    2
    186
    Loading More Posts
    • 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.
    • Ahti
      Ahti last edited by aha_1980

      I am trying to convert current system time to day month year format and store that in database table.

      main.qml

      QSqlQuery q;
      QString date = QDate::currentDate().toString("dddMMMyyyy");
      q.exec("insert into users values(1, 'David', 'London', '"+date+"')");
      qDebug() << "Error: " << q.lastError();
      

      error:

      QSqlError("22007", "QPSQL: Unable to create query", " ERROR: invalid input syntax for type date: \"SunFeb2020\"\nLINE 1: ...ers values(1, 'David', 'London', 'SunFeb202....\n ^\n(22007)")

      what is a signature ?? Lol

      1 Reply Last reply Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        Hi
        If the database table type is of type date, it wont like a string formatted as
        SunFeb2020 so you need to match the toString format to the one expceted by the DBMS.

        1 Reply Last reply Reply Quote 5
        • mrjj
          mrjj Lifetime Qt Champion last edited by

          Hi
          If the database table type is of type date, it wont like a string formatted as
          SunFeb2020 so you need to match the toString format to the one expceted by the DBMS.

          1 Reply Last reply Reply Quote 5
          • First post
            Last post