I am trying to convert a date gathered from a QDateEdit into datetime.date for use in a sqlite3 database. I have seen that in PyQt4 you could use toPyDateTime however it doesnt seem to be in PyQt5. If this function is completely gone is there a way to convert QDate into a string?
You want this->getBookingDate(). toString("yyyy. MM. dd") .
Qt5 current date & timeQDate cd = QDate::currentDate(); The QDate::currentDate static function returns the current date. QTime ct = QTime::currentTime(); The QTime::currentTime static function returns the current time.
What version of PyQt5 are you using?
>>> from PyQt5.QtCore import QDate, QDateTime
>>> QDate.currentDate().toPyDate()
datetime.date(2014, 3, 17)
>>> QDateTime.currentDateTime().toPyDateTime()
datetime.datetime(2014, 3, 17, 19, 9, 45, 974000)
This is using Qt-5.2.1 with PyQt-5.2 or PyQt-5.1.1.
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