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.
QDate QDate::fromString ( const QString & s, Qt::DateFormat f = Qt::TextDate ) [static] Returns the QDate represented by the string s, using the format f, or an invalid date if the string cannot be parsed. Note for Qt::TextDate: It is recommended that you use the English short month names (e.g. "Jan").
QDate::QDate(int y, int m, int d) Constructs a date with year y, month m and day d. The date is understood in terms of the Gregorian calendar. If the specified date is invalid, the date is not set and isValid() returns false .
[static] QDateTime QDateTime::currentDateTime() Returns the current datetime, as reported by the system clock, in the local time zone. See also currentDateTimeUtc(), QDate::currentDate(), QTime::currentTime(), and toTimeSpec().
You want this->getBookingDate().toString("yyyy.MM.dd")
. For further info, read the documentation.
in PySide2 you can use this:
self.dateEdit.date().toString("yyyy.MM.dd")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With