2010-05-31 39 views
0

之間我有很多紀錄,我的數據庫至極盤點日期包含時間字段(例如2010-05-23十七點45分57秒)。
我想算例如之間的所有記錄15:00和15:59(這一切可以通過從其他一天,一個月或一年)。我怎樣才能做到這一點?Django的 -

+1

http://stackoverflow.com/questions/917996/how-do-i-filter-by-time- IN-A-日期時間場 – 2010-05-31 12:13:59

回答

0

您可以將日期時間字段轉換成Julian Dates ,然後做一個直接比較:

# 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