I created a list of values of datetime objects
a=design_list.values_list('date_submitted')
So I get:
[(datetime.datetime(2012, 10, 21, 13, 56, 24),), (datetime.datetime(2012, 10, 21, 10, 33, 58),), etc...
I'm trying to convert them to timestamps with, say:
timestamps[0] = a[0].strftime("%s")
But I get the error:
AttributeError: 'tuple' object has no attribute 'strftime'
Can anyone tell me what I'm doing wrong?
I added flat=True to the query:
a=design_list.values_list('date_submitted', flat=True)
Which gives:
[datetime.datetime(2012, 10, 21, 13, 56, 24), datetime.datetime(2012, 10, 21, 10, 33, 58),
Which then can be converted.
You're referring to the tuple instead of the first element of the tuple. Try a[0][0].strftime('%s').
>>> a = [(datetime.datetime(2012, 10, 21, 13, 56, 24),)]
>>> a[0][0].strftime('%s')
'1350852984'
This is the reason for why you got the error, but as you correctly pointed out, flattening the resulting list is the right approach here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With