Django - count date between
I have many record in my database which contains datetime field (e.g. 2010-05-23 17:45:57).
I want to count all records betwee开发者_如何学JAVAn e.g. 15:00 and 15:59 (it all can by from other day, month or year). How can I do this?You can convert the datetime fields into Julian Dates and then do a straight comparison:
# Input is a list with the time of all the records, t_record_all
# Loop over all the records
counter = 0
jd_low = ... #(this is your lower time limit in JD)
jd_hi = ... # (this is your higher time limit in JD)
for t_record in t_record_all:
# Convert the time to julian date format
jd_record = ... #(do your conversion here)
if (jd_low <= jd_record <= jd_hi):
# increment record counter
counter = counter + 1
print counter
精彩评论