QDate into QString

user1871869 picture user1871869 · Sep 16, 2013 · Viewed 7.4k times · Source

I have a question about PyQt4. I have a date that is of a type QDate and I want to simply turn it into a string format as opposed to QDate format. For example, if the date is 09/16/2013, I would want to change it into a string form of September 16, 2013 if possible.

I played around with toString but I think that only works with C++ (unless I am mistaken).

Answer

Viktor Kerkez picture Viktor Kerkez · Sep 16, 2013

Documentation is your friend ;)

>>> date = QtCore.QDate.fromString('20130916', 'yyyyMd')

# PySide
>>> date.toString('MMMM d, yyyy')
u'September 16, 2013'

# PyQt4
>>> date.toString('MMMM d, yyyy')
PyQt4.QtCore.QString(u'September 16, 2013')
>>> unicode(date.toString('MMMM d, yyyy'))
u'September 16, 2013'