Convert QDate to Qstring?

27,971

Solution 1

You want this->getBookingDate().toString("yyyy.MM.dd"). For further info, read the documentation.

Solution 2

in PySide2 you can use this:

self.dateEdit.date().toString("yyyy.MM.dd")
Share:
27,971
Letholdrus
Author by

Letholdrus

Updated on July 11, 2022

Comments

  • Letholdrus
    Letholdrus almost 2 years

    I have trouble converting QDate to QString. See the code below:

    cout << QString("\nBooking Date: %1").arg(QDate::toString(this->getBookingDate() &YYYY.mm.dd)
    

    When I try to compile this it gives me:

    ‘YYYY’ was not declared in this scope
    

    Yet the documentation says:

    "Returns the date as a string. The format parameter determines the format of the result string..." and goes on to list the format strings.

    I am new to Qt so if I am missing the obvious please excuse the ignorance.