Reputation: 51
Have spent a few hours trying to figure this out unsuccessfully.
I've imported some 'date' (not datetime) fields from MySQL into a python list. If I print the list, the values will show up as:
my_list = [[100, datetime.date(2013, 3, 11)], [101, datetime.date(2013, 4, 13,)],[102,datetime.date(2013, 4, 13)]
(...where 101, 102, 103 are my corresponding event_id's, you can disregard them)
I've found that the following will get the conversion correct:
unix_time = time.mktime(datetime.date(2009,2,17).timetuple())
However, if I try to do something like:
for x in my_list:
x[1] = time.mktime(datetime.date(x[1]).timetuple())
It will not work.
Upvotes: 0
Views: 510
Reputation: 621
First solution was ugly, new edit:
for x in my_list:
x[1] = time.mktime(x[1].timetuple())
should get you your list. No need to wrap the datetime.date in another datetime.date
Upvotes: 3