Hi all I have a time field check_time that i want to check every day (ex. 13:40) and then do something if the check_time is close to the time I run the query. In other words I run the query every 10 minutes and want to select all the checkpoint records that their check_time is max 5 minutes (300 sec.) earlier then my current time
db.define_table('checkpoint', Field('name') Field('check_time','time') ) Because the query might involve crossing midnight I need to to fix the check_time to a date of the current date by adding the number of seconds from the beginning of the universe and then compering it to the current time in the query, all converted to seconds. First I get the number of seconds from the beginning of the universe to the beginning of today: 1. beginning of the universe: epochstart = datetime.datetime.fromtimestamp(0) 2. beginning of today in seconds: # convert today to a datetime so it can be used in a delta dnow=datetime.datetime.now().date() todaystart=datetime.datetime(dnow.year, dnow.month, dnow.day, 0, 0) # datetime of beginning of today todayseconds=(todaystart-epochstart).total_seconds() 3. get the seconds of the current time: now = datetime.datetime.now() nowseconds=(now-epochstart).total_seconds() 4. Now we have everything needed for the query and I try to 'fix' the check_time to be comparable to the current time that might span a day limit (because of the -300) rows=db((todayseconds+db.checkpoint.check_time.epoch()>(nowseconds-300)&(todayseconds+db.checkpoint.check_time.epoch()<=nowseconds))).select() 5. The problem is that the DAL will not take the: todayseconds+db.checkpoint.check_time.epoch() expression. TypeError: unsupported operand type(s) for +: 'int' and 'Expression' An alternative can be to 'fix' the current time to the number of seconds from the beginning of today and if the nowseconds-300 <0 then to add 86400 and to use this number instead of the low limit: nowseconds-300 Hope for better ideas -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.