Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

argument must be 9-item sequence, not datetime.datetime

Web app is breaking on the following line;

start_time = int(time.mktime(start)) * 1000

The error is a TypeError - argument must be 9-item sequence, not datetime.datetime

How to I convert my datetime.datetime to a 9-item-sequence?

like image 844
Mark Corrigan Avatar asked Dec 19 '22 12:12

Mark Corrigan


1 Answers

Instead of passing datetime object directory, use datetime.timetuple method:

>>> int(time.mktime(start)) * 1000
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: argument must be 9-item sequence, not datetime.datetime

>>> int(time.mktime(start.timetuple())) * 1000
1406215043000L

BTW, if you use Python 3.3+, you don't need to use time.mktime. Use datetime.timestamp:

>>> start.timestamp()
1406215043.0
>>> int(start.timestamp()) * 1000
1406215043000
like image 187
falsetru Avatar answered Jan 09 '23 23:01

falsetru