This is my "Request" class/Table:
class Request(BaseModel):
TIME_STAMP = DateTimeField(default=datetime.datetime.now)
MESSAGE_ID = IntegerField()
With peewee, I want to select from the table, all of the "requests" that have occurred over the past 10 minutes. Something like this:
rs = Request.select().where(Request.TIME_STAMP-datetime.datetime.now<(10 minutes))
But well, I'm not entirely sure how to get the difference between the TIME_STAMP and the current time in minutes.
EDIT: I've tried Gerrat's suggestion, but Peewee seems to cry:
/usr/local/lib/python2.7/dist-packages/peewee.py:2356: Warning: Truncated incorrect DOUBLE value: '2014-07-19 15:51:24'
cursor.execute(sql, params or ())
/usr/local/lib/python2.7/dist-packages/peewee.py:2356: Warning: Truncated incorrect DOUBLE value: '0 0:10:0'
cursor.execute(sql, params or ())
I've never used peewee, but if you're just subtracting two timestamps, then you'll get back a datetime.timedelta object. You should be able to just compare it to another timedelta object then. Something like:
rs = Request.select().where(Request.TIME_STAMP-datetime.datetime.now()
<(datetime.timedelta(seconds=10*60)))
EDIT ...Looking a little closer at peewee, above may not work. If it doesn't then something like the following should:
ten_min_ago = datetime.datetime.now() - datetime.timedelta(seconds=10 * 60)
rs = Request.select().where(Request.TIME_STAMP > ten_min_ago)
It seems slightly odd that your timestamp in your database would be greater than the current time (what your select assumes)...so you may want to add the time delta and subtract the values the other way around (eg if you want to select records in the last 10 minutes).