Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Undefined behaviour of QDate when converted to string



  • 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)")


  • Lifetime Qt Champion

    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.


  • Lifetime Qt Champion

    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.


Log in to reply