我有以下代码:
init()
我收到以下错误:
from datetime import datetime as dt
import time
import datetime
TODAY_DATE = datetime.date.today()
THREE_MONTH = datetime.timedelta(weeks=12)
FOUR_MONTH = datetime.timedelta(weeks=16)
START_DAY = TODAY_DATE - FOUR_MONTH
END_DAY = TODAY_DATE - THREE_MONTH
x = agent_coll_obj.find({ "created_at": {"$gte" : datetime.datetime(START_DAY),
"$lt": datetime.datetime(END_DAY) }})
print x
我试图以此SO question为指导。我试图只使用整个日期而不是每个日期的年,月和日变量。
答案 0 :(得分:0)
from datetime import datetime as dt
import time
import datetime
TODAY_DATE = datetime.date.today()
THREE_MONTH = datetime.timedelta(weeks=12)
FOUR_MONTH = datetime.timedelta(weeks=16)
START_DAY = TODAY_DATE - FOUR_MONTH
END_DAY = TODAY_DATE - THREE_MONTH
x = agent_coll_obj.find({ "created_at": {"$gte" : START_DAY,
"$lt": END_DAY }})
print x
您可以像这样使用datetime.datetime:
In [2]: datetime.datetime?
Docstring:
datetime(year, month, day[, hour[, minute[, second[, microsecond[,tzinfo]]]]])
The year, month and day arguments are required. tzinfo may be None, or an
instance of a tzinfo subclass. The remaining arguments may be ints or longs.
File: /usr/local/opt/pyenv/versions/2.7.8/lib/python2.7/lib-dynload /datetime.so
Type: type
答案 1 :(得分:0)
datetime.datetime函数需要specify年,月,日。