conversion of datetime Field to string in django queryset.values_list()

A date and time, represented in Python by a datetime.datetime instance.

You can get a string representation of a DateTimeField casting it directly:

# obj = qs[0][0] ? or qs[0][1] ?

You’ll get result like this (in this example I use since a DateTimeField is represented by datetime.datetime is the same behavior):

>>> now =
>>> str(now)
'2013-06-26 00:14:26.260524'

if you want less information or formatted in other mode you can use strftime() function for format them. see:

>>> now.strftime('%Y-%m-%d %H:%M')
'2013-06-26 00:14'

Leave a Comment