Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you convert QDate in PyQt5 to a datetime.date?

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?

like image 462
user1921942 Avatar asked Mar 17 '14 09:03

user1921942


People also ask

How do I convert Qdatetime to Qstring?

You want this->getBookingDate(). toString("yyyy. MM. dd") .

How do I display current date and time in Qt?

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.


1 Answers

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.

like image 54
ekhumoro Avatar answered Sep 27 '22 22:09

ekhumoro