I'm unsure how I can accomplish filtering my database using only the time field. Right now I have a class called DatabasePolgygon
class DatabasePolygon(dbBase):
__tablename__ = 'objects'
begin_time = Column(DateTime) # starting time range of shape
end_time = Column(DateTime) # ending time range of shape
# Other entries not relevant to this question
begin_time, and end_time may be equal to such values as 2006-06-01 14:45:23
, they represent the X-axis range that an object(in this case a shape over a plot) covers. I want to allow advanced searching for my users, specifically asking for all objects that appear within a range of time. How can I accomplish this with the DateTime
field however?
# Grab all shapes that appear above this certain time
query_result = query_result.filter(
DatabasePolygon.begin_time >= datetime.strptime(rng['btime']), %H:%M:%S')
)
The problem is i'm comparing a datetime object with a Y-m-d H-M-S
to an object with only a H-M-S
. An example scenario would be if a user wants all objects, regardless of year/month/day, that appear beyond the range of 14:45:24, so we would have rng['btime']=14:45:24
and begin_time=2006-06-01 14:45:23
which doesn't seem to actually filter anything when compared.
Is there some way I can efficiently compare times within this column of data? I'd love to be able to do something like
# Grab all shapes that appear above this certain time
query_result = query_result.filter(
DatabasePolygon.begin_time.time() >= datetime.strptime(rng['btime']), %H:%M:%S').time()
)