Reputation: 4158
I get the invalid format string error when I try to run the below code (last line), not sure where I am missing the point:
import datetime
DAYS = 2
SINCE = datetime.datetime.now() - datetime.timedelta(days=DAYS)
params = "?fields=feed.since(" + SINCE.strftime("%s") + ").limit(1),name,updated_time&"
Any suggestions would be much appreciated !!
Upvotes: 1
Views: 10002
Reputation: 161
it works fine for me (Python 2.7). If it is part of a query and it is failing on that part, maybe you can use another date format like:
params = "?fields=feed.since(" + SINCE.strftime("%Y-%m-%d %H:%M:%S") + ").limit(1),name,updated_time&"
Please note that capital "S", will give you the seconds of that datetime object.
Upvotes: 0
Reputation: 27899
It really depends on which format suits you, but if you need timestamp use:
int(time.mktime(SINCE.timetuple()))
Upvotes: 0
Reputation: 1494
You have to use "%S" because "%s" is not defined in the method you called : https://docs.python.org/2/library/datetime.html#datetime.strftime
import datetime
DAYS = 2
SINCE = datetime.datetime.now() - datetime.timedelta(days=DAYS)
params = "?fields=feed.since(" + SINCE.strftime("%S") + ").limit(1),name,updated_time&"
You should add what format you need for your application.
Upvotes: 3