Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
890 views

Convert QDate in PyQt5 To A Datetime - Date PDF

A QDate can be converted to a datetime.date in PyQt5 by using the toPyDate() method on the QDate. Similarly, a QDateTime can be converted to a datetime.datetime by using the toPyDateTime() method. These methods were present in PyQt5.1.1 and PyQt5.2 for converting between Qt and Python datetime types.

Uploaded by

Marcel Chis
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
890 views

Convert QDate in PyQt5 To A Datetime - Date PDF

A QDate can be converted to a datetime.date in PyQt5 by using the toPyDate() method on the QDate. Similarly, a QDateTime can be converted to a datetime.datetime by using the toPyDateTime() method. These methods were present in PyQt5.1.1 and PyQt5.2 for converting between Qt and Python datetime types.

Uploaded by

Marcel Chis
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

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?

1 Answer

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.

You might also like