Python - Qdate to datetime conversion

Asked

Viewed 92 times

3

I need to convert an input date by a Qcalendar to datetime (from lib datetime). How can I do it?

1 answer

3


The Qdatetime has a function toPyDateTime that returns an object datetime pattern

from PyQt5.QtCore import QDate, QDateTime

#usando Date
QDate.currentDate().toPyDate()
datetime.date(2017, 3, 17)

#usando DateTime
QDateTime.currentDateTime().toPyDateTime()
datetime.datetime(2017, 3, 17, 19, 9, 45, 974000)
  • Right, I tried that and returned that exception: Except: 'Qdate' Object has no attribute 'toPyDateTime'

  • You are using Pyqt5 or Pyside?

  • I am using Pyqt5!

  • I saw that in your error you use Qdate along with toPyDateTime but in fact it only supports toPyDate. Take a look at the code above that I edited

Browser other questions tagged

You are not signed in. Login or sign up in order to post.