7

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?

ekhumoro
  • 115,249
  • 20
  • 229
  • 336
user1921942
  • 121
  • 1
  • 2
  • 9

1 Answers1

22

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.

ekhumoro
  • 115,249
  • 20
  • 229
  • 336