I try to convert MySQl datetime to same in Python.On debug there is
ValueError: time data '2001-06-04T11:30:35' doesn't match format %Y-%m-%dT%H:%M:%S . In MySQL there is no 'T' in data.I tried format with 'T' and without.
I saw this article How to convert the following string to python date? .
This is code:
query = QSqlQuery ()
query.exec_("SELECT birthday FROM vista.user ")
def countAge(birthday):
birthday = datetime.strptime(str(birthday), "%Y-%m-%dT%H:%M:%S.%f")
today = date.today()
age = today.year - birthday.year
if today.month < birthday.month:
age -= 1
elif today.month == birthday.month and today.day < birthday.day:
age -= 1
if age >= 0 :
return age
ages = []
index = 0
while (query.next()):
print(query.value(index).toString())
ages.append(countAge(query.value(index).toString()))
index = index + 1
What is a problem?
print(query.value(index).toString())?